Sub topic 2
Semantic elements: header, nav, main, section, footer
What you should already know
This chapter assumes you can write basic HTML tags and attributes, and that you can open a page in a browser and inspect it with developer tools. It builds on the four-part page model from the previous chapter.
The working model
A semantic element is an HTML element whose name describes its role, not its appearance. A <div> says nothing about its contents. A <footer> says "closing information". Browsers, search engines, and assistive technology such as screen readers read these names and use them to understand the page.
Semantic elements do not change how the page looks by default. They change what the page means. You add the look with CSS.
| Element | Role | Typical use per page |
|---|---|---|
| `header` | Introductory content: logo, site name, navigation | Once for the site header |
| `nav` | A block of links for moving around | One or more, each labeled |
| `main` | The central content unique to this page | Exactly one visible |
| `section` | A themed group of content, usually with a heading | Many |
| `footer` | Closing content: copyright, secondary links | Once for the page |
A page skeleton
This skeleton uses all five elements. 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 diagram shows how the elements nest.
How each element behaves
header
A header holds introductory content for its nearest ancestor. At the top level of body, it is the site header. It usually contains the site name or logo and the primary navigation. It is not limited to the top of the page. An article can have its own header with a title and date.
nav
Use nav for major blocks of navigation links, not for every group of links. A list of links inside a paragraph does not need it. Putting the links in a ul gives screen readers a count of items, which helps users judge the menu's size.
main
main wraps the content that is unique to this page. The header, footer, and repeated sidebars stay outside it. A page should have one visible main. Browsers and screen readers use it as a shortcut target, so a second one confuses users.
section
A section groups related content under a theme, and it should normally start with a heading. If you only need a box to attach styles to, use a div. A useful test: if you can't name the section with a heading, it probably isn't a section.
footer
A footer holds closing information for its nearest ancestor. At the top level it is the page footer: copyright, legal links, contact details, and secondary links.
Common errors
- Using
divfor everything. The page looks the same but has no landmarks. Screen reader users lose their shortcuts. - Several
mainelements. Keep one visiblemainper page. - Using
sectionas a styling wrapper. Usedivwhen there is no theme or heading. - Putting
headerorfooterinsidemainand expecting them to be page landmarks. Insidemain, they describe only their nearest section or article. - Choosing an element for its default look. Pick by meaning, then style with CSS.
Exercise
A developer wraps the site logo and menu in a div, puts the page's unique content in two main elements (one per column), and closes with a div class="footer". Which three changes make the structure semantic?
Show answer
Replace the first div with header and put the menu links in a nav. Merge the two main elements into one main and use div or section elements for the columns. Replace div class="footer" with a footer.
Exercise
You have a box that only gives a gray background to a group of buttons. It has no heading. Should it be a section?
Show answer
No. It has no theme or heading, and it exists only for styling, so a div is the correct element.