How many <main> elements may an HTML document contain, and what does <main> do for users and assistive technology?
answer
- one visible per document
- hidden ones are the exception
- cannot nest inside header, nav, aside
- the skip link's destination
- no role attribute needed
basics
~20 sA document may have only one <main> that is not hidden, and it must not sit inside <article>, <aside>, <footer>, <header> or <nav>. It marks the dominant content and is what skip links and screen-reader shortcuts jump to.
solid answer
~50 s`<main>` marks the dominant content of the document — everything that is not site-wide furniture like the header, primary nav, sidebar and footer. HTML allows at most one `<main>` per document that lacks the `hidden` attribute; extra hidden ones are legal so a single-page app can keep inactive views in the DOM, but only one may be visible at a time. It also must not be a descendant of `<article>`, `<aside>`, `<footer>`, `<header>` or `<nav>` — it is a top-level region, not a nested one. The payoff is jump-to-content: it exposes the `main` landmark, screen readers offer a direct shortcut to it, a "skip to content" link can target its `id`, and reader modes use it as a hint for what to extract. Two visible `<main>` elements break that promise, because "the main content" stops being a single unambiguous destination.
go deeper
Remember that a page has one <main>, that site header, nav and footer go outside it, and that you never need role="main" on it.
State the rule precisely — at most one <main> without the hidden attribute, and never nested inside article, aside, footer, header or nav — and explain what the skip link and landmark shortcut depend on.
Talk about how this holds up in a single-page app: which view owns main during a route change, where focus goes after navigation, and how you would catch a second visible main in review or automated checks.
Decide and document where main lives in a layout system — shell versus page component — so no feature team can nest a second one, and make the skip-link contract part of the layout, not each page.
## What <main> means `<main>` wraps the content that is unique to this document — the part a reader came for. Everything repeated across the site (masthead, primary navigation, site-wide sidebar, footer) belongs outside it. The element carries the `main` landmark role implicitly, so you never need `role="main"` on it. ## The one-per-document rule, stated precisely The rule people repeat is "only one `<main>` per page". The specification's actual constraint is slightly more useful: a document must not have more than one `<main>` element that does **not** have the `hidden` attribute. That exception exists for applications that keep several views in the DOM at once — a router can hold three `<main>` elements and mark two of them `hidden`, and the document is still conforming, because only one is exposed at a time. There is a second, separate constraint that candidates often miss: `<main>` must not be a descendant of `<article>`, `<aside>`, `<footer>`, `<header>` or `<nav>`. `<main>` is a top-level region of the document; nesting it inside a card or a sidebar is invalid, and the reason is the same as the first rule — there is one dominant content region, not one per component. ```html <body> <header>…site masthead and primary nav…</header> <main id="content"> <h1>Refund policy</h1> <p>…the unique content of this page…</p> </main> <footer>…site-wide footer…</footer> </body> ``` ## Why it matters in practice **Skip links.** The single most common accessibility affordance on the web is a link at the very top of the page reading "Skip to main content", pointing at the main region's id: ```html <a class="skip-link" href="#content">Skip to main content</a> ``` Keyboard users who would otherwise tab through forty navigation links on every page press Tab once and Enter. That link needs one unambiguous destination. **Screen-reader shortcuts.** Screen readers expose landmarks in a rotor or menu and offer keys to move between them, with the main landmark as a first-class destination. "Take me to the content" is the single most-used structural command, and it is only meaningful if exactly one region claims to be the content. **Content extraction.** Reader modes and similar tools use structural hints, including `<main>`, when deciding which part of a page is the article body. Marking site furniture as main, or marking nothing at all, makes that guess worse. ## Two visible mains: what actually breaks Nothing crashes. The page renders identically, because `<main>` has no visual behaviour beyond block display. What breaks is the contract: the landmark list now shows two entries both labelled "main", the skip link takes you to whichever id it names while the other region is equally "the content", and validators flag the document as non-conforming. It is a silent accessibility regression, which is precisely why interviewers like the question — it cannot be caught by looking at the screen. ## Related judgment calls Does a sidebar of related links go inside `<main>`? Generally no — if it is tangential and repeated across pages, it is an `<aside>` sibling of `<main>`. But an `<aside>` that is tangential to *this specific article* can legitimately sit inside `<main>` next to the article it relates to; the test is what the content is tangential *to*. Should `<main>` contain the page's top-level heading? Conventionally yes: the `<h1>` describing this document's content lives inside `<main>`, not in the site header. That keeps the heading and the region it titles together. Does `<main>` need a label? Almost never. There is one main landmark, its role already announces it as "main", and adding `aria-label="Main content"` produces the redundant announcement "main content, main". Labels are for landmarks that repeat.
- Why does the specification allow multiple <main> elements when all but one are hidden?So client-side applications can keep several views in the DOM and swap which one is active. Only one non-hidden `<main>` may exist at any moment, which preserves the guarantee assistive technology depends on — exactly one region claims to be the current page's content — while letting a router pre-render or cache the others.
- Where should the skip link live, and why is it usually invisible until focused?It should be one of the very first focusable elements in the document, so the first Tab press reaches it. It is typically positioned off-screen and brought into view on `:focus`, because the affordance only matters to keyboard users while it is focused. Hiding it in a way that removes it from the tab order entirely defeats the purpose.
- Should <main> be given an aria-label?Normally no. There is one main landmark per document and its role is already announced, so a label like "Main content" just adds a redundant word. Labelling is the tool for landmarks that repeat — several navs, several regions — where a name is the only way to tell them apart.
saying these in an interview costs you the question
- Putting a <main> inside each card or component
- Believing multiple <main> elements are always invalid
- Writing role="main" on a div instead of using <main>
- Placing the site header and nav inside <main>
- Adding aria-label="Main" to the only main landmark