Home HTML Tags <main> HTML <main> Tag Definition
Definition and Usage The <main> element marks the dominant content of the <body> — material that is unique to this page or app screen.
Keep site chrome outside it: <header> , <nav> , <aside> , and <footer> for repeated logos, menus, sidebars, and copyright. Prefer native <main> over role="main".
Baseline · Widely available. Not deprecated. Stable across modern browsers since about July 2015. Implicit ARIA role: main.
One visible main. A document must not have more than one <main> without the hidden attribute.
Syntax
HTML Syntax <main>
<!-- unique page content -->
</main> Both start and end tags are required. Place it where flow content is allowed, as a hierarchically correct main landmark.
Reference
Attributes <main> has no element-specific attributes — only globals. These globals matter most in practice:
Attribute Description Try it (none required) A bare <main> wraps the page’s primary content Try itidTarget for a “skip to main content” link Try ithiddenHides a main; allows another visible main when switching views Advanced Page layout Pair with header, nav, and footer outside main Try it
Try it
Live Preview Switch layouts to see what belongs in <main> versus outside it.
Code
HTML Examples Short, copy-ready snippets. Use Try It Yourself for a live editor.
1. Basic main 2. Skip link 3. Page layout Example 1 — Primary Page Content Wrap the unique topic of the page in <main>.
<main>
<h1>Apples</h1>
<p>The apple is the fruit of the apple tree.</p>
<article>
<h2>Granny Smith</h2>
<p>These juicy green apples make a great pie filling.</p>
</article>
</main> Apples The apple is the fruit of the apple tree.
Granny Smith These juicy green apples make a great pie filling.
How It Works Open <main> around the page’s central topic.Put unique content inside — headings, articles, forms that are the point of the page.Nest sectioning elements like article when they belong to that topic.Close with </main> before site footer chrome.Example 2 — Skip to Main Content Add an id so assistive tech users can jump past repeated navigation.
<a href="#main-content">Skip to main content</a>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
<main id="main-content">
<h1>Welcome</h1>
<p>Primary article starts here.</p>
</main> How It Works Place a skip link early in the body (often first focusable control).Set href="#…" to match the main’s id.Keep nav outside main so skipping past it makes sense.Test with keyboard — Tab to the link, Enter jumps to main.Example 3 — Header, Main, Footer One visible main between shared header and footer.
<header>
<p>Site name</p>
</header>
<main>
<h1>Today’s lesson</h1>
<p>Only this page’s unique content lives here.</p>
</main>
<footer>
<p>Copyright notice</p>
</footer> Today’s lesson Only this page’s unique content lives here.
How It Works Put shared branding in header (and menus in nav).Put the unique lesson in main — one visible main.Put copyright in footer outside main.Reuse the same shell on other pages; only main’s insides change. Edge Cases & Pitfalls Most main bugs are multiple mains, chrome inside main, or missing skip targets.
count More than one visible main Only one non-hidden <main> per document (MDN / HTML).
content Repeated chrome inside main Do not park site logos, global nav, or copyright in main unless they are the page’s purpose.
a11y Skip link without a matching id href="#main-content" must match id="main-content" on the main (or another target).
roles Do not stack role="main" Native <main> already exposes the landmark. Extra roles add noise.
nesting Hierarchically correct placement Do not nest main inside another main, or inside elements that break the landmark pattern.
Compatibility
Browser Support The <main> element is core HTML in every modern browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
<main> Widely available since about July 2015. Landmark behavior and reader-mode hints work in current engines.
98% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer IE 11*
Partial / polyfill era <main> Widely supported
Bottom line: Safe for everyday layouts. Use one visible main; add a skip link for better keyboard access.
Remember
Key Takeaways Role: <main> marks the dominant, unique page content.
Count: only one visible main (others may be hidden).
Chrome out: keep global nav, logos, and footers outside.
Skip link: give main an id and link to it early in the body.
One line: one visible <main> for this page’s unique content.
UA style
Default CSS Settings Browsers treat main as a block container (exact UA sheets vary):
Layout (columns, max-width, spacing) is up to your CSS — the element’s job is semantics and landmarks.
Frequently Asked Questions What is the HTML main tag used for? The main element marks the dominant content of the document body — the topic or primary functionality of that page.
How many main elements can a page have? Only one main that is not hidden. Extra main elements may use the hidden attribute when switching views.
Should nav, header, and footer go inside main? No for site-wide chrome. Keep repeated navigation, logos, sidebars, and copyright outside main unless that content is the page’s primary purpose.
Does main affect the document outline? No. Unlike sectioning headings, main does not change the document outline; it is a landmark for the primary content.
Should I add role="main"? Prefer the native main element. Avoid adding role="main" on top of it; use role only if you must polyfill a non-main container for very old browsers.
How do skip links work with main? Give main an id and link to it with href="#that-id" near the start of the body so keyboard and screen-reader users can jump past repeated chrome.
Next: map Define image maps with clickable areas using the HTML map element.
map tutorial → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
12 people found this page helpful
Helpful Share Copy link Suggestion