Skip to content

<main> - Main Content Element

Landmark HTML5

The <main> element represents the dominant content of the document’s body. It contains the central topic or main functionality of the page, excluding content that is repeated across multiple pages like navigation, headers, footers, and sidebars.

Result
<main>
<!-- Primary page content -->
</main>

The <main> element has no element-specific attributes.

This element supports all global attributes.

The main content of a blog post, excluding navigation and footer:

Result

The product details are the main content, while navigation and promotional banners are outside:

Result

Search results are the main content:

Result

The dashboard content is main, while the app navigation is outside:

Result
  • Primary article or blog post content
  • Search results
  • Product details
  • Dashboard content
  • Form content (for form-focused pages)
  • Unique page content
  • Site headers and logos
  • Global navigation menus
  • Sidebars with related links (unless they’re integral to the main content)
  • Site-wide footers
  • Copyright notices
  • Advertising banners
  • Search forms (unless the page is a search page)

Only one <main> element should be visible at a time:

<!-- Correct: Single main element -->
<body>
<header>...</header>
<main>
<h1>Page Content</h1>
</main>
<footer>...</footer>
</body>
<!-- Also correct: Multiple main elements with hidden -->
<body>
<main id="primary-content">
<h1>Default Content</h1>
</main>
<main id="alternative-content" hidden>
<h1>Alternative View</h1>
</main>
</body>

Provide a skip link for keyboard users:

Result

The <main> element should not be nested inside <article>, <aside>, <footer>, <header>, or <nav>:

<!-- Wrong: main inside article -->
<article>
<main>
<h1>Content</h1>
</main>
</article>
<!-- Correct: main contains article -->
<main>
<article>
<h1>Content</h1>
</article>
</main>

Combine <main> with other semantic elements for best structure:

<body>
<header>
<h1>Site Name</h1>
<nav><!-- Site navigation --></nav>
</header>
<main>
<article>
<header>
<h2>Article Title</h2>
</header>
<section>
<h3>Section 1</h3>
<p>Content...</p>
</section>
</article>
<aside>
<!-- Related content that's part of the main content -->
</aside>
</main>
<footer>
<!-- Site footer -->
</footer>
</body>

The <main> element has an implicit ARIA role of main, creating a landmark that assistive technologies can navigate to:

<!-- These are equivalent -->
<main>Content</main>
<div role="main">Content</div>

Screen reader users can jump directly to the main content using landmark navigation:

  • JAWS: ; key to cycle through landmarks
  • NVDA: D key to jump to landmarks
  • VoiceOver: Use rotor to navigate to landmarks

If you have multiple <main> elements (with hidden), label them:

<main id="primary" aria-label="Primary content">
<h1>Default View</h1>
</main>
<main id="alternative" aria-label="Alternative content" hidden>
<h1>Alternative View</h1>
</main>
BrowserVersion
Chrome26+
Firefox21+
Safari7+
EdgeAll versions
IE11+ (with polyfill for IE 9-10)
<!-- Wrong: Multiple visible main elements -->
<body>
<main>
<h1>Content 1</h1>
</main>
<main>
<h1>Content 2</h1>
</main>
</body>
<!-- Correct: Hide all but one -->
<body>
<main>
<h1>Visible Content</h1>
</main>
<main hidden>
<h1>Hidden Alternative</h1>
</main>
</body>
<!-- Wrong: Navigation in main -->
<main>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
</main>
<!-- Correct: Navigation outside main -->
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
<main>
<h1>Page Content</h1>
</main>