HTML <main> Tag

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

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.

HTML Syntax

syntax.html
<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.

Attributes

<main> has no element-specific attributes — only globals. These globals matter most in practice:

AttributeDescriptionTry it
(none required)A bare <main> wraps the page’s primary contentTry it
idTarget for a “skip to main content” linkTry it
hiddenHides a main; allows another visible main when switching viewsAdvanced
Page layoutPair with header, nav, and footer outside mainTry it

Global Attributes

The <main> tag also supports the Global Attributes in HTML.

Live Preview

Switch layouts to see what belongs in <main> versus outside it.

Demo structure only — one visible main with unique content.

Structure

Gecko facts

Geckos are usually small nocturnal lizards.

Basic main — primary content only.

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Primary Page Content

Wrap the unique topic of the page in <main>.

HTML
<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>
Try It Yourself

How It Works

  1. Open <main> around the page’s central topic.
  2. Put unique content inside — headings, articles, forms that are the point of the page.
  3. Nest sectioning elements like article when they belong to that topic.
  4. 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.

HTML
<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>
Try It Yourself

How It Works

  1. Place a skip link early in the body (often first focusable control).
  2. Set href="#…" to match the main’s id.
  3. Keep nav outside main so skipping past it makes sense.
  4. Test with keyboard — Tab to the link, Enter jumps to main.

Example 3 — Header, Main, Footer

One visible main between shared header and footer.

HTML
<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>
Try It Yourself

How It Works

  1. Put shared branding in header (and menus in nav).
  2. Put the unique lesson in main — one visible main.
  3. Put copyright in footer outside main.
  4. 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.

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.

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.

Default CSS Settings

Browsers treat main as a block container (exact UA sheets vary):

default.css
main {
  display: block;
}

Layout (columns, max-width, spacing) is up to your CSS — the element’s job is semantics and landmarks.

Frequently Asked Questions

The main element marks the dominant content of the document body — the topic or primary functionality of that page.
Only one main that is not hidden. Extra main elements may use the hidden attribute when switching views.
No for site-wide chrome. Keep repeated navigation, logos, sidebars, and copyright outside main unless that content is the page’s primary purpose.
No. Unlike sectioning headings, main does not change the document outline; it is a landmark for the primary content.
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.
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

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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