There are five HTML elements that describe the structure of a page: header, nav, main, article, and footer.
On screen they look like plain boxes. In fact each one carries a promise about what it contains, and that promise is used by screen readers, by search engines, and by features of the browser itself. A page that keeps its promises is much easier for every one of those tools to understand.
This is the first lesson in the Semantic HTML and Accessibility module, and the next lesson in this module is about "How Do alt Text and ARIA Help Screen Readers?".
What does each element mean?
<body>
<header>
<a href="/" class="logo">Acme</a>
<nav aria-label="Primary">
<ul>
<li><a href="/docs">Docs</a></li>
<li><a href="/pricing">Pricing</a></li>
</ul>
</nav>
</header>
<main>
<article>
<h1>How semantic layout works</h1>
<p>Article content that would still make sense on its own.</p>
</article>
</main>
<footer>
<p>© Acme</p>
</footer>
</body>Each one means something specific.
The header is the introductory content for its nearest section. That is usually the site header at the top of the page, but it can also appear inside an article, where it introduces only that article.
The nav is a block of the major navigation links. It is the part of the page that helps a reader move around the site.
The main is the unique content of the page, and there has to be exactly one.
The article is a self-contained piece that would still make sense if it were syndicated on its own.
The footer is the closing content for its section. That is the copyright notice, the links, and the contact details.
Why does the difference between the article and the main matter?
Because they answer different questions, and most pages need both answers.
The main answers "what is unique to this page?", and exactly one element has it.
The article answers "what is a discrete piece of content?", and a page can have many.
<main>
<h1>Latest tutorials</h1>
<article>
<h2><a href="/tutorials/python">Learning Python</a></h2>
<p>Posted 12 October</p>
</article>
<article>
<h2><a href="/tutorials/css">Understanding CSS</a></h2>
<p>Posted 10 October</p>
</article>
</main>The practical test for an article is the syndication test. If a reader could copy the article into a newsletter or a feed and it would still be complete and understandable, then it belongs in an article.
A sidebar with a list of links does not, so it stays a plain aside.
Where do the section, the aside and the div fit in?
The section is a thematic group with a heading, and it usually has an article inside it.
The aside is content that is tangentially related to what is around it.
The div has no meaning at all, which makes it the right choice only when nothing more specific fits.
<div> <!-- generic grouping -->
<section> <!-- thematic grouping with a heading -->
<article> <!-- self-contained composition -->
<aside> <!-- tangentially related content -->What do you actually gain?
There are three concrete benefits.
Screen readers can offer landmark navigation. That is a menu of "main", "navigation", and "content", so a user can jump to the part of the page they want instead of reading it in a straight line.
Search engines understand the primary content of a page when it is inside main, and they can treat each article as a separate entry when the page is a listing of many pieces.
The browser itself gets a skip mechanism. Pressing a key that focuses the address bar and then tabbing moves the focus into the page content in many browsers, and the main element is what it lands on.
<!-- the landmark is explicit and named -->
<nav aria-label="Breadcrumb">...</nav>
<nav aria-label="Footer links">...</nav>When a page has more than one navigation region, each one needs its own aria-label. Otherwise a screen reader announces several identical "navigation" landmarks, and the user cannot tell them apart.
That is the one case where an ARIA attribute earns its place on a structural element.
What do the landmarks look like in a real page?
Most pages end up with three navigation landmarks and two content landmarks, and the browser's accessibility panel lists all of them, so you can see whether the labels are useful.
<body>
<header>
<a href="/" class="logo">Acme</a>
<nav aria-label="Primary">...</nav>
</header>
<main>
<h1>How semantic layout works</h1>
...
</main>
<aside aria-label="Related tutorials">...</aside>
<footer>
<nav aria-label="Footer">...</nav>
<p>© Acme</p>
</footer>
</body>There are three things about that structure that are worth noting.
The header and the footer are per section, so a page with a grid of cards where each card has its own header has several header elements, and that is correct. Nothing is wrong with a page that has more than one of them.
The aside is a separate landmark from the main, which means a screen reader user can skip the related links if they want the article.
And each landmark has a name, so "navigation" appears twice with different labels instead of two identical entries.
How do the headings work inside these elements?
The outline of a page is built from the headings wherever they appear, and it is separate from the landmark structure.
A page can have perfect landmarks and a broken outline, or the reverse. Neither one repairs the other.
The two systems answer different questions. The landmarks say where in the page a thing is, and the headings say what it is about.
<main>
<h1>How semantic layout works</h1> <!-- the page title -->
<section>
<h2>Why structure matters</h2> <!-- a section of the page -->
<p>...</p>
</section>
<section>
<h2>Choosing the right element</h2>
<article>
<h3>When to use article</h3> <!-- a discrete piece inside it -->
<p>...</p>
</article>
</section>
</main>Because headings are the only thing that gives a long page a navigable structure, the section element works best when it contains a heading.
A section with no heading is a grouping with no theme, and a div says that more honestly. If you cannot name the theme, do not reach for the section element.
Quick reference
- There is one main per page. It is the unique content.
- The article is for content that stands alone, and there can be many of them.
- The header and the footer are per section, and not just per page.
- The nav is for the major navigation, and you give it a label when there is more than one.
- The semantic elements style exactly like a div. The difference is the meaning.
Try it yourself: take a page that is built entirely from divs and rebuild it with the five structural elements. Then open the accessibility tree in the developer tools and compare the list of landmarks before and after. Add a second nav and watch what a screen reader would announce.