Sub topic 2
Semantic elements: header, nav, main, section, footer
This chapter assumes you know basic HTML tags and attributes, can write simple CSS selectors, and can open a page in a browser and inspect it with developer tools. You will learn what semantic elements are, what each major one means, and which mistakes show up most often when people use them.
What "semantic" means
A semantic element is an HTML element whose name describes the role of its content. A <footer> is a footer. A <div> says nothing about its content.
Compare two ways to mark up the top of a page:
<div class="header">
<div class="nav">
<div class="link">Menu</div>
</div>
</div><header>
<nav aria-label="Primary">
<ul>
<li><a href="/menu">Menu</a></li>
</ul>
</nav>
</header>Both can look identical once styled. The second version gives the browser and assistive technology real information. Screen readers expose some of these elements as landmarks, which are named regions a user can jump between. Search engines and reader modes can also find the main content more easily. The <div> version offers none of this, and its <div> "link" is not even keyboard-focusable.
Semantic elements do not change how a page looks beyond a few default styles, such as block display. Their value is in meaning.
The elements and their roles
The table lists the elements this chapter covers and the landmark role each one can expose.
| Element | Meaning | Landmark role |
|---|---|---|
| `<header>` | Introductory content for the page or a section | `banner` when it belongs to the page, otherwise none |
| `<nav>` | A block of major navigation links | `navigation` |
| `<main>` | The central content unique to this page | `main` |
| `<section>` | A themed group of content, usually with a heading | `region` only if it has an accessible name |
| `<footer>` | Closing information for the page or a section | `contentinfo` when it belongs to the page, otherwise none |
Two points in the table cause most of the confusion. First, <header> and <footer> change meaning depending on where they sit. Second, <section> is not a landmark unless you name it.
A page skeleton
The following page uses all five elements. The header, main, and footer mark the three major regions. The hero is the first section inside <main>.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Acme Bakery</title>
</head>
<body>
<header>
<a href="/">Acme Bakery</a>
<nav aria-label="Primary">
<ul>
<li><a href="/menu">Menu</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
</header>
<main>
<section class="hero">
<h1>Fresh bread, baked every morning</h1>
<p>Order ahead and pick up warm loaves on your way to work.</p>
<a href="/menu">See the menu</a>
</section>
<section>
<h2>Our specialties</h2>
<p>Sourdough, rye, and seasonal pastries.</p>
</section>
</main>
<footer>
<p>© 2026 Acme Bakery</p>
<a href="/privacy">Privacy</a>
</footer>
</body>
</html>The next diagram shows how those elements nest.
`<header>`
A <header> holds introductory content: a logo or site name, navigation, a search form, or a title block. It is not limited to the top of the page.
- When
<header>is a direct child of<body>, it is the page header and maps to thebannerlandmark. - When
<header>sits inside<article>,<section>,<aside>, or<nav>, it only introduces that container. It is not a landmark.
This means a page can have several <header> elements. A blog post, for example, might wrap its title and date in a <header> inside the <article>. Only the one that is a direct child of <body> is the site banner.
`<nav>`
A <nav> wraps a block of major navigation links. Use it for the primary menu, a footer link group, a table of contents, or pagination. Do not put every group of links in a <nav>. A row of "related articles" inside the body text is just links.
Keep these rules in mind:
- Put links in a list (
<ul>) inside the<nav>. Screen readers announce the number of items, which helps users orient themselves. - A page may have more than one
<nav>. Give each one a distinctaria-labelsuch as "Primary" or "Footer". Without labels, a screen reader user hears "navigation" twice and cannot tell the two apart. - Do not write "navigation" in the label. The role is already announced, so
aria-label="Primary"is read as "Primary navigation".
`<main>`
The <main> element contains the content that is the point of this particular page. Content that repeats across pages, such as the site header, primary navigation, and footer, belongs outside it.
Rules:
- Use exactly one visible
<main>per page. (A second one is allowed only if the extra one has thehiddenattribute, as in some single-page apps.) - Do not nest
<main>inside<header>,<footer>,<nav>,<article>, or<aside>. - Give it an
idif you plan to add a skip link. Chapter later in this tutorial covers skip links in detail. Here is the short form:
<a class="skip-link" href="#main">Skip to main content</a>
<main id="main">
...
</main>The main landmark is the one that screen reader users jump to most often. If it is missing, they must move through the header and navigation on every page.
`<section>`
A <section> groups content that shares one theme, and it should normally start with a heading. Think of it as a chapter of the page.
The most common error is using <section> as a styling wrapper. If you only need a box to attach a background or padding to, use a <div>. A useful test: if the group would not appear as an entry in an outline of the page, it is probably not a <section>.
Sections become landmarks only when you name them. You can do that by pointing to the heading:
<section aria-labelledby="specialties-title">
<h2 id="specialties-title">Our specialties</h2>
<p>Sourdough, rye, and seasonal pastries.</p>
</section>With aria-labelledby, the section is exposed as a region landmark called "Our specialties". Without it, the section is invisible to landmark navigation, which is usually fine. Naming every section creates a long landmark list and makes it harder to use, so name only the sections a user might want to jump to.
Choosing between section, article, and div
| Use | When |
|---|---|
| `<section>` | The content is one themed part of a larger whole and has a heading. |
| `<article>` | The content makes sense on its own, such as a blog post, a product card, or a comment. |
| `<div>` | You need a generic wrapper for layout or styling only. |
`<footer>`
A <footer> holds closing information: copyright, legal links, contact details, or secondary navigation. Like <header>, it depends on its parent.
- A
<footer>that is a direct child of<body>maps to thecontentinfolandmark. - A
<footer>inside an<article>or<section>is the footer of that container, for example an author line under a post. It is not a landmark.
A site footer often contains its own <nav>. Label it so it differs from the header's navigation:
<footer>
<nav aria-label="Footer">
<ul>
<li><a href="/privacy">Privacy</a></li>
<li><a href="/terms">Terms</a></li>
</ul>
</nav>
<p>© 2026 Acme Bakery</p>
</footer>Common errors
- Multiple
<main>elements. Only one visible<main>is valid. Check each template, since a layout file and a page file may both add one. <header>and<footer>inside<main>, expecting landmarks. They are valid there, but they act as section-level elements and are not page banners.- Unlabeled repeated
<nav>elements. Addaria-labelto each one. <section>without a heading. An untitled section has no clear purpose. Add a heading or switch to<div>.- Wrapping the whole page in
<section>. The page body already has structure from<header>,<main>, and<footer>. - Using
<nav>for every link group. This floods the landmark list. - Putting the site header's content in
<main>. Repeated content then gets read as part of the unique page content.
Checking your work
You can verify the landmarks without a screen reader. In Chrome or Edge developer tools, open the Elements panel, select the Accessibility tab, and look at the accessibility tree. Each landmark appears with its role, and each named element shows its name. In Firefox, the Accessibility panel shows the same tree. Confirm that:
- The page has one
banner, onemain, and onecontentinfo. - Every
navigationhas a distinct name. - Any
regionyou expected is present and named.
Summary
<header>,<main>, and<footer>as direct children of<body>define the three page-level landmarks.<header>and<footer>inside other containers only scope to that container.<nav>is for major link groups. Label each one when there is more than one.<main>appears once per page and holds the content unique to it.<section>is a themed group with a heading. It becomes a landmark only with an accessible name.- Prefer
<div>when you need a wrapper for styling alone.
Exercise
A page has a <header> as a direct child of <body>, a <nav> inside it, a <main>, and a <footer> as a direct child of <body> that also contains a second <nav>. Neither <nav> has an aria-label. Inside <main>, a <section> with an <h2> has no aria-labelledby. Which landmarks does a screen reader expose, and what two changes would improve the page?
Show answer
The screen reader exposes banner (the header), two unnamed navigation landmarks, main, and contentinfo (the footer). The <section> is not a landmark because it has no accessible name. Improve the page by adding distinct labels to the two navs, such as aria-label="Primary" and aria-label="Footer", so users can tell them apart. Then add aria-labelledby pointing to the section's <h2> only if users would want to jump to that section. Otherwise leave it unnamed.
Exercise
You are building a product card that has a title, a photo, a price, and a short description. The card could be reused on other pages. Would you use <section>, <article>, or <div> for the card, and why?
Show answer
Use <article>. The card makes sense on its own and can be reused or syndicated elsewhere. A <section> is for a themed part of a larger whole, and a <div> carries no meaning. If a grid wrapper around many cards is only for layout, that wrapper can be a <div>.
Exercise
A teammate puts the site logo and primary menu inside <main> "so they are all in one place." Name one problem this causes and say where the elements should go.
Show answer
Screen reader users who jump to the main landmark land on the logo and menu instead of the page's unique content, and the repeated content is treated as part of that page. Move the logo and menu into a <header> that is a direct child of <body>, with the menu in a <nav aria-label="Primary">, and keep only page-specific content in <main>.