Landmarks and Page Layout Elements
header, nav, main, aside, footer and search map to landmark roles. See when each one earns its role, and why scope and labels change the result.
Landmarks and Page Layout Elements
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- `header`, `nav`, `main`, `aside`, `footer` and `search` are exposed as landmarks: `banner`, `navigation`, `main`, `complementary`, `contentinfo` and `search`. A landmark lets assistive technology jump straight to a region.
- `header` and `footer` are landmarks only as direct page-level elements. In a test, a `header` inside `main` and a `footer` inside a `section` reported no landmark role.
- A page has one `main` landmark. In a test two `<main>` elements both stayed in the DOM, so the browser will not stop you. Pick one.
- When there are several landmarks of one type, label them. `<nav aria-label="Primary">` and `<nav aria-label="Footer">` are announced with their names, and unlabelled ones are both just 'navigation'.
- Use landmarks for the big regions only. Over-marking turns a map into noise, and a `div` has no role at all.
A map of the page
Open a long book and you use the contents page, the chapter headings and the index to find your place. A web page has the same need, and for someone who can’t see the screen it’s more urgent. A screen reader user can’t glance at a layout and spot “that’s the menu on the left”. They need the page to say which parts are which.
Landmark elements do that. They’re ordinary elements that browsers map to landmark roles, and screen readers list them so a person can jump to “main” or “navigation”. Before these elements existed, pages were built from <div class="header"> and <div class="nav">, and class names mean nothing to software. The semantic HTML lesson in the frontend roadmap makes the broader case. This lesson is the elements themselves.
The elements and what they become
I ran a page with all of these through headless Chromium 159 and read the accessibility tree:
| Element | Role in the tree | When |
|---|---|---|
<header> |
banner |
page-level only |
<nav> |
navigation |
a block of major navigation links |
<main> |
main |
the unique content of the page |
<aside> |
complementary |
related content on the side |
<footer> |
contentinfo |
page-level only |
<search> |
search |
a search form or filter area |
<section aria-label="x"> |
region |
only with a name |
<form aria-label="x"> |
form |
only with a name |
A div gets no role at all. In a test, a page made of <div class="header">, <div class="nav"> and <div class="main"> came out as one run of plain text, with nothing to jump to.
Scope: header and footer
header and footer change meaning with their position. At the top level of the page, a header is the banner and a footer is the contentinfo. Inside article, section, main, aside or nav, they only introduce or close that piece of content. In a test:
- A
<header>directly in the body was reported asbanner. - A
<header>inside<main>, and a<footer>inside a<section>, were reported with no role. - The
<footer>directly in the body wascontentinfo.
That’s the rule you want: a blog post can have its own header with title and date, without claiming to be the site banner.
One main, and labels for repeats
A page should have one main. The browser won’t enforce it: in a test, two <main> elements both stayed in the DOM, and the second one was only dropped from the tree when it had the hidden attribute. It’s an authoring rule, so validators and audits check it.
When a landmark type repeats, label each one. In a test, <nav aria-label="Main"> was announced as navigation "Main", and <nav aria-labelledby> pointing at a heading took that heading’s text. Two unlabelled nav elements were reported as two identical navigation entries. Use aria-label or aria-labelledby. Naming comes up again in accessible names and descriptions.
A <section> is the trap. Without a name it isn’t a landmark. In a test an unnamed <section> produced only its heading and text, while <section aria-labelledby="h"> produced region "Named". The next lesson, article, section and the outline, explains when a section deserves a name.
Restraint
Landmarks work as a map only if they’re sparse. If every block is a landmark, the list a screen reader shows is as long as the page. Mark the big regions: banner, navigation, main, complementary, footer, and a search if there is one. Put everything else in ordinary elements. The accessibility tree lesson shows this tree directly.
What the video covers
The embed is ByteGrad’s “Why & When to Use Semantic HTML Elements over Divs” (December 2022, about 12 minutes). Its chapters are introduction to semantics (0:00), a basic HTML boilerplate (0:47), structuring main content (2:13), footer structure (3:44), real-world examples from Stripe (4:23) and MDN (7:15), and when to use divs (10:21). It is about semantic elements in general and isn’t specific to landmark roles, and I could not read a transcript, so I describe it only from the chapters. The role table, the scoping tests and the labelling tests are this lesson’s own. Kevin Powell’s semantic HTML lesson, linked below, has a chapter on landmark regions for accessibility.
Where this fits
This opens the semantic structure group and builds on the text elements and links from the previous one. Next is the part of the page inside main: article, section and the outline. The tree behind all of this gets its own treatment in the accessibility tree and native semantics.
Check yourself
A page has a site header, a menu, the article content and a copyright line. Which elements mark them?
`<header>` for the site header, `<nav>` for the menu, `<main>` around the article content, and `<footer>` for the copyright line, each at the page level. Together they produce the banner, navigation, main and contentinfo landmarks.
You put a `<header>` inside an `<article>`. Does it become the page's banner?
No. Inside `article`, `section`, `main`, `aside` or `nav`, a `header` has no landmark role, and in a test it was not reported as `banner`. It only labels that piece of content. The same holds for `footer` and `contentinfo`.
A page has a primary menu and a footer menu, both `<nav>`. What should you add?
An accessible name on each, such as `aria-label="Primary"` and `aria-label="Footer"`. In a test the labelled ones were announced as 'navigation Main' and so on, while unlabelled ones were two identical 'navigation' entries a person cannot tell apart.
Why use `<main>` instead of a `<div id="main">`?
`main` is a landmark, and a screen reader can jump to it and skip the repeated header and menu. A `div` with an id has no role, and in a test a page made of divs showed up as plain text with nothing to jump to.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.