Sub topic 4
Marking up navigation with nav, lists, and labels
This chapter covers the HTML that turns a list of links into a navigation region that assistive technology can find, name, and move through. It assumes you know basic HTML and CSS, how links and lists work, and how the box model sizes elements. You do not need JavaScript yet. Later chapters add the skip link, current-page state, and submenus on top of this markup.
Why markup matters before styling
A sighted visitor recognizes a navigation bar from its position and appearance. A screen reader user has no such cue. They rely on the structure the browser exposes to the accessibility tree, which is the version of the page that assistive technology reads. If your menu is a row of div elements with click handlers, that tree contains nothing that says "navigation".
Three native HTML features fix this, and each costs almost nothing:
- The
navelement marks a region as navigation. - A
ullist groups the links and announces how many there are. - An
aria-labelgives each navigation region its own name.
The nav element and landmarks
The nav element has an implicit ARIA role of navigation. A role that lets users jump straight to a region is called a landmark. Screen readers list the landmarks on a page, and users can skip between them with a single key or menu choice. Wrapping your main links in nav therefore adds a "Navigation" entry to that list without any extra attributes.
Do not add role="navigation" to a nav element. It repeats what the element already says and adds nothing.
Use nav for major blocks of navigation links, such as the primary menu, a footer link directory, a table of contents, or a breadcrumb trail. Do not use it for every group of links. A row of social icons, or two links under a form, is not a navigation region. If every cluster of links becomes a landmark, the landmark list fills with noise and users stop trusting it.
Why a list
Navigation is a set of parallel items, so a list describes it correctly. When a screen reader enters a list, it typically announces "list, 4 items" and the position of each item. The user learns the size of the menu before reading it and knows when it ends.
The standard structure is nav, then ul, then one li per link:
<header>
<nav aria-label="Primary">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/products">Products</a></li>
<li><a href="/pricing">Pricing</a></li>
<li><a href="/support">Support</a></li>
</ul>
</nav>
</header>A ul is correct because the order of the items is a design choice, not a sequence the user must follow. Use ol only when order carries meaning, as in a multi-step checkout or a numbered guide.
Removing the bullets without breaking the list
Browsers draw bullets and left padding on lists, so you reset them in CSS. There is a known catch. Safari with VoiceOver has historically stopped announcing a list as a list when list-style: none is applied. The widely used workaround is to add role="list" to the ul. Treat this as a defensive measure for that combination and test with it if VoiceOver users matter to you.
nav ul {
display: flex;
gap: 1.5rem;
margin: 0;
padding: 0;
list-style: none;
}
nav a {
display: inline-block;
padding: 0.75rem 0.5rem;
color: inherit;
text-decoration: none;
}The padding on the links, not on the li elements, makes the whole padded area clickable. That also matters for touch targets, which a later chapter covers.
Labeling each navigation region
A page often has more than one nav: a primary menu in the header and a directory in the footer. If both are unnamed, the screen reader's landmark list shows "navigation, navigation" and the user cannot tell them apart.
Give each one an accessible name. Use aria-label when the name does not appear as visible text, or aria-labelledby when a visible heading already names the region.
<nav aria-label="Primary">
<!-- main menu -->
</nav>
<nav aria-labelledby="footer-nav-title">
<h2 id="footer-nav-title">Explore</h2>
<ul>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>Follow these naming rules:
- Make each name unique on the page.
- Keep names short, such as "Primary", "Footer", "Breadcrumb", or "Table of contents".
- Leave the word "navigation" out of the name. The screen reader already says "navigation landmark", so
aria-label="Primary navigation"is read as "Primary navigation navigation". - Write names in the page's language, because they are read aloud and are not translated for you.
If a page has exactly one nav, a label is optional. Adding one is still a good habit, because pages tend to gain a second nav later.
Where nav sits in the page
The header element, when it is a direct child of body, maps to the banner landmark. Placing the primary nav inside it is the common pattern. The main element holds the page's unique content. The nav itself does not have to be inside header, but keeping it there helps the structure read clearly.
<body>
<header>
<a href="/">Example Co.</a>
<nav aria-label="Primary">
<ul>
<li><a href="/products">Products</a></li>
<li><a href="/pricing">Pricing</a></li>
</ul>
</nav>
</header>
<main id="main">
<h1>Pricing</h1>
</main>
<footer>
<nav aria-label="Footer">
<ul>
<li><a href="/privacy">Privacy policy</a></li>
</ul>
</nav>
</footer>
</body>Link text and structure inside the list
The words inside each a are the label users hear, and screen readers can read out a list of all links on a page, stripped of their surroundings. Link text must therefore make sense on its own. "Pricing" works. "Click here" does not.
If a link contains only an icon, give it a text alternative. Visually hidden text or an aria-label on the link both work. Do not rely on a title attribute, which is inconsistently exposed.
Keep every item an actual a element with an href. A link with a real href is focusable with the Tab key, opens in a new tab with a middle click, and works before any JavaScript loads. A span with a click handler has none of these.
Common errors
| Mistake | Effect | Fix |
|---|---|---|
| Menu built from `div` elements | No landmark, no list, not keyboard focusable | Use `nav`, `ul`, `li`, `a` |
| Two `nav` elements without names | Landmark list shows identical entries | Add a unique `aria-label` to each |
| `aria-label="Main navigation"` | Announced as "Main navigation navigation" | Use `aria-label="Main"` |
| `role="navigation"` on a `nav` | Redundant, adds noise to code | Remove the role |
| `nav` wrapped around every link group | Landmark list becomes cluttered | Reserve `nav` for major blocks |
| Links with no `href` | Not focusable by keyboard | Add a real `href` |
Putting it together
A solid navigation starts as plain, well-formed HTML that works without any styling or script. The structure is nav with a unique name, containing a ul, containing li elements, each holding an a with real text and a real href. Everything in the next chapters, including the skip link, the current-page marker, and disclosure submenus, builds on that foundation.
Exercise
A page has a header menu and a footer link directory, both marked up as <nav> with no other attributes. A screen reader user opens the landmarks list. What do they see, and what two changes fix it? Also, a developer proposes aria-label="Footer navigation" for the second one. What is wrong with that name?
Show answer
The list shows two entries that are both just "navigation", so the user cannot tell which is which. Fix it by adding a unique aria-label to each, for example aria-label="Primary" on the header nav and aria-label="Footer" on the footer nav. The name "Footer navigation" is wrong because the screen reader already announces the role, so the user hears "Footer navigation navigation". Use "Footer" instead.
Exercise
You remove the bullets from a navigation ul with list-style: none. Name one reason you still use a ul rather than plain a elements separated by line breaks, and one precaution for Safari with VoiceOver.
Show answer
A list lets screen readers announce the number of items and each item's position, so users know the size of the menu. The precaution is to add role="list" to the ul, because Safari with VoiceOver has historically dropped the list semantics when list-style: none is applied.