Live Preview
Primary content highlighted inside a semantic main landmark:
Article Title
This is the unique primary content of the page.

By the end of this tutorial, you’ll structure pages with <main> so primary content is semantic, accessible, and SEO-friendly.
Wrap unique page content in <main> tags.
Use a single visible main landmark per document.
Help screen readers jump to primary content.
Place main between header, nav, aside, and footer.
Choose semantic markup over generic divs.
Target id="main-content" for accessibility.
<main> Tag?The main element (<main>) is a semantic HTML5 landmark that wraps the primary content of a document — the central topic or application functionality. It excludes content repeated across pages such as site headers, navigation bars, footers, and sidebars.
Each page should have exactly one visible <main> element. Do not put site-wide navigation, logos, or copyright footers inside it — those belong in <header>, <nav>, and <footer>.
Using <main> improves accessibility by giving assistive technology a clear landmark, and helps search engines understand which content is unique to the page.
Wrap the unique primary content between opening and closing <main> tags:
<main>
<!-- Your main content goes here -->
</main><main> per HTML document.article, aside, footer, header, or nav.<main> inside another <main>.<body> (directly or indirectly).| Pattern | Code Snippet | Notes |
|---|---|---|
| Basic main | <main>...</main> | Primary content wrapper |
| Skip link target | <main id="main-content"> | For “Skip to content” links |
| CSS hook | class="primary-content" | Style the main area |
| Inside body | <body><main>...</main></body> | Correct placement |
| Exclude nav | Nav outside main | Site nav is not main content |
| Count limit | One visible main | No nested mains |
<main> vs <div>| Feature | <main> | <div> |
|---|---|---|
| Semantics | Primary content landmark | Generic container |
| Accessibility | Announced by screen readers | No landmark role |
| Per page | One visible element | Unlimited |
| SEO | Signals primary content | Neutral |
| Use today? | Yes — preferred | Only when no semantic tag fits |
<main> vs <article>| Element | Scope | Best for |
|---|---|---|
<main> | One per page — all primary content | Page-level landmark |
<article> | Many per page allowed | Self-contained posts, cards, widgets |
| Together | main contains article elements | Blog feed inside main |
| Nesting rule | main must not be inside article | article can be inside main |
The <main> element has no unique attributes — only global attributes apply:
id GlobalUnique identifier for skip links and in-page anchors. Common value: main-content.
id="main-content"class GlobalCSS hook for layout and styling the primary content area.
class="primary-content"tabindex A11yUse tabindex="-1" so main receives focus when a skip link is activated.
tabindex="-1"<main id="main-content" class="primary-content" tabindex="-1">
<!-- Primary page content -->
</main>Basic main wrapper, welcome content, and a full semantic page layout with header, nav, aside, and footer.
Primary content highlighted inside a semantic main landmark:
This is the unique primary content of the page.
Add id for skip links and class for CSS styling.
<main id="main-content" class="primary-content">
<p>This is the main content area of the page.</p>
</main>Use <main> on every page to wrap blog posts, product details, dashboard views, documentation content, and any unique primary content — always excluding site chrome like global nav and footers.
Wrap headings and body copy that represent the page’s central topic.
<main>
<h1>Welcome to Our Website</h1>
<p>Explore our latest products and services.</p>
</main>Place <main> between site chrome and beside <aside> for related content.
<header>Site Header</header>
<nav>...</nav>
<main>
<h1>Article Title</h1>
<p>Primary content here.</p>
</main>
<aside>Related links</aside>
<footer>Copyright</footer>Style the primary content area with layout, spacing, and max-width constraints:
max-width Readable line lengthmargin: auto Center contentpadding Inner spacingmin-height Fill viewportmain {
max-width: 960px;
margin: 0 auto;
padding: 2rem 1.5rem;
min-height: 60vh;
}
main h1 {
margin-bottom: 1rem;
line-height: 1.3;
}Styled main content area
Centered, padded primary content with a comfortable reading width.
The <main> landmark is essential for accessible page structure:
<a href="#main-content">Skip to main content</a> and matching id on main.tabindex="-1" on main so it receives focus after a skip link is activated.<h1> for a logical document outline.Header, nav, and footer wrap repeated site chrome outside main.
Articles, product details, and page-specific content live inside <main>.
Assistive technology maps main to the primary content region.
Users and search engines instantly recognize where primary content begins.
The <main> element is an HTML5 semantic landmark with full support in all modern browsers and Internet Explorer 11+.
From IE11 to the latest mobile browsers — main is a standard landmark for accessible, structured pages.
Bottom line: Use <main> on every page for semantic, accessible primary content in all production environments today.
The <main> tag is a cornerstone of semantic HTML5. It identifies the unique primary content of each page, improves accessibility landmarks, and helps both users and search engines focus on what matters most.
Use exactly one visible main per page, keep site chrome outside it, and pair it with skip links and proper heading hierarchy for the best results.
<main> per pageid="main-content" for skip links<main>Bookmark these before you ship — they’ll keep your page structure semantic and accessible.
main wraps the page’s central topic.
FoundationScreen readers navigate to main directly.
A11ySingle visible main element only.
RuleSemantic meaning beats generic containers.
ComparisonArticles live inside main, not vice versa.
StructureHTML5 landmark in all modern browsers.
Compatibility<nav> outside main. In-page table-of-contents nav may appear inside main when it serves that specific content.<body>, not nested inside article, aside, footer, header, or nav.Build a page with header, nav, main, aside, and footer in the interactive editor.
6 people found this page helpful