Open a shopping app on your phone. Along the bottom of the screen there's a row of icons, one in colour and the rest grey. Without thinking, you know which page you're on and what to tap to move.
That row of icons is navigation. The job of navigation is to tell a visitor two things: where they are, and how to get somewhere else. It's like the floor map in a shopping mall. The list of floors and their shops is the main navigation. The red "You are here" dot is the current-page marker, for the page that is open now. Sometimes there is also a route from the entrance to the shop you want: that is a breadcrumb. A good map is visible without searching for it, and it has only one red dot.
Navigation patterns
| Pattern | Suits | At Mist Homestay |
|---|---|---|
| Links on top (top nav) | a site with few main pages | Home, Rooms, Location, Bookings |
| Bottom tab bar (a row of buttons at the bottom of the screen) | a phone app with 3 to 5 destinations you switch between often | Mrs. Sri's dashboard: Bookings, Calendar, Rooms, Account |
| Sidebar (a menu column at the side) | an app with many sections, on a wide screen | Mrs. Sri's dashboard on a laptop |
| Hamburger (a menu hidden behind one button) | links that don't fit and are rarely used | Privacy policy, Terms, About Mrs. Sri |
| Breadcrumb (the path of pages) | a page that sits below another page | Home › Rooms › Terrace Room |
These patterns combine. The guest site uses links on top, and the room page adds a breadcrumb.
Wrap it in nav, mark the current page
This is the guest site's main navigation. Its links are written as a list (<ul>, with one <li> for each link) inside <nav>. The Rooms link is marked as the current page:
<nav aria-label="Main navigation">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/rooms" aria-current="page">Rooms</a></li>
<li><a href="/location">Location</a></li>
<li><a href="/bookings">Bookings</a></li>
</ul>
</nav>
<style>
nav a { display: block; padding: 12px 10px; color: #475569; text-decoration: none; }
nav a[aria-current="page"] { color: #15803d; font-weight: 700; box-shadow: inset 0 -3px #15803d; }
</style>
<nav>is the HTML element for a block of navigation. A screen reader (a program that reads the page aloud for blind users) lists it as a landmark, a jump point. So its user can go straight to the navigation without reading the whole page.aria-labelgives that block a name. The name is required when the page has more than one<nav>, for example the main navigation and a breadcrumb, so the two have different names.aria-current="page"marks the link to the page that is open now. A screen reader announces it as "current page". Only one link may carry it, because there is only one "You are here" dot.- The CSS uses the same attribute as its selector (the part of CSS that says which elements a rule applies to):
nav a[aria-current="page"]. So the mark the eye sees and the mark a screen reader user hears are always the same. - The mark is more than colour. Green alone breaks WCAG 1.4.1 (colour must not be the only difference). That is why there is weight 700 and a 3px underline, which is drawn with a
box-shadowon the inside (inset). - Every link has an
href(the address the link goes to) that points at its own page, the current-page link too.
In the exercise, the starter is a <nav> with three links: Home, Products, About. Add aria-label="Main navigation" to the <nav>, and aria-current="page" to the Home link only.
A breadcrumb on the room page
The Terrace Room page sits one level below the Rooms page. A breadcrumb shows the path, and gives a way up one level to the Rooms page:
<nav aria-label="Breadcrumb" class="crumbs">
<ol>
<li><a href="/">Home</a></li>
<li><a href="/rooms">Rooms</a></li>
<li><a href="/rooms/terrace" aria-current="page">Terrace Room</a></li>
</ol>
</nav>
<style>
.crumbs ol { display: flex; flex-wrap: wrap; list-style: none; padding: 0; }
.crumbs a { display: inline-block; padding: 4px 0; }
.crumbs li + li::before {
content: ""; display: inline-block; width: 6px; height: 6px; margin: 0 10px 2px 6px;
border-top: 2px solid #475569; border-right: 2px solid #475569; transform: rotate(45deg);
}
</style>
<ol>(a numbered list) is used because the order means something: from Home, down to Rooms, then to the Terrace Room.list-style: nonehides the numbers.flex-wrap: wrapmoves links to the next line when they don't fit.- The last link goes to this page itself, so that link carries
aria-current="page". On this page, the Rooms link in the main navigation may be markedaria-current="true", which means "the section you're in", because the Terrace Room is in the Rooms section. So there is still only one link that says "page". - The arrow between the links is made with
::before(an extra element that CSS creates) on every<li>except the first (li + li). It has no content (content: ""), and the arrow is the top and right border of a small box that is rotated. Written as a›character, the arrow gets read out by some screen readers between every link. padding: 4px 0makes each link 29px tall, above the 24px minimum in WCAG 2.5.8.
On a phone: visible links, a tab bar, or a hamburger
We measured Mrs. Sri's page at 375px wide, in Chromium, WebKit and Firefox. The result was the same in all three:
| Pattern | Links visible without a tap | Smallest link box |
|---|---|---|
| Links on top, in their own row under the site name | 4 of 4, fit in one row | 63.1 × 48px |
| Bottom tab bar, icon and label | 4 of 4 | 93.8 × 56px |
| Closed hamburger | 0 of 4 | Menu button 68 × 48px |
The limits for a touch target (the area you can tap) from the Density & Scale lesson: WCAG 2.5.8 at least 24 × 24px, Apple 44 × 44pt, Material 48 × 48dp. All three patterns meet those limits. The difference is in which links are visible.
Mrs. Sri once thought of hiding all four links (Home, Rooms, Location, Bookings) behind a "Menu" button to keep things tidy. Do guests still use the navigation as often as when the links are visible? Guess before you look at the numbers.
Nielsen Norman Group (NN/g, a UX research company) tested this in 2016 with 179 participants and 6 sites. On phones, hidden navigation was used in 57% of cases. Partly visible navigation (some links showing, the rest in a menu) was used in 86% of cases. Tasks also took 15% longer when the navigation was hidden. On desktop the gap was wider: hidden navigation 27%, the others 48 to 50%. So the answer to the guess: no. What isn't visible gets used less.
Choices for Mrs. Sri:
- Guest site: four short links fit in one row, so just show them on top.
- Mrs. Sri's dashboard on her phone: a bottom tab bar. Material recommends a tab bar for 3 to 5 top-level destinations, each with an icon and a label.
- Hamburger: for links that really don't fit and are rarely looked for. If you use one, build its button from
<button aria-expanded="false" aria-controls="menu">Menu</button>.aria-expandedtells a screen reader whether the menu is open, andaria-controlspoints to the menu that the button opens. Write "Menu" as the button's text, and keep the most important destinations outside the menu.
⚠️ Navigation that gets guests lost
aria-current="page"on two links. The nav was copied from another page and the marker came with it, so a screen reader says two pages are open. In the exercise, an answer like this is rejected.- The current page differs only by colour. Colour-blind users don't see the difference. Add weight or an underline.
- A hamburger for four links. The links fit, but they're hidden. Show them.
- A link without
href, or a clickable<div>. It can't be reached with the Tab key, and it isn't a link to a screen reader. Every link needs a filled-inhref. - Two
<nav>elements with no name. A screen reader lists two "navigation" landmarks that sound exactly the same. Give them anaria-label.
TL;DR: Navigation answers "where am I" and "where else can I go". Wrap it in <nav aria-label="...">: <nav> marks a block of navigation, and aria-label gives it a name (required when there's more than one <nav>). Mark the link to the open page with aria-current="page", on one link only. Then make that link bold through the same attribute in the CSS (nav a[aria-current="page"]), not with colour alone. Choose the pattern from how many destinations there are and how much they matter. Links on top suit a site with few pages. A bottom tab bar (a row of buttons at the bottom of the screen) suits 3 to 5 app destinations on a phone, and a sidebar (a menu column at the side) a big app on a wide screen. A breadcrumb (the path of pages, a numbered list <ol> inside <nav aria-label="Breadcrumb">) is for nested pages. A hamburger (a menu behind one button) is only for links that don't fit and are rarely used. A study by NN/g (a UX research company): on phones, hidden navigation was used in 57% of cases, partly visible navigation in 86%.
⚡ nav, and one current-page mark
Write:
<nav aria-label="Main navigation">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/rooms" aria-current="page">Rooms</a></li>
<li><a href="/location">Location</a></li>
</ul>
</nav>
<style>
nav a[aria-current="page"] { color: #15803d; font-weight: 700; box-shadow: inset 0 -3px #15803d; }
</style>
Meaning: <nav> wraps the list of navigation links. It becomes a landmark (a jump point) that a screen reader, a program that reads the page aloud for blind users, can go to directly. aria-label gives it a name. aria-current="page" marks the link to the page that is open now, and goes on one link only. The CSS uses the same attribute as its selector (the part of CSS that picks which elements a rule styles), with weight and an underline, not colour alone.
⚡ A breadcrumb for nested pages
Write:
<nav aria-label="Breadcrumb" class="crumbs">
<ol>
<li><a href="/">Home</a></li>
<li><a href="/rooms">Rooms</a></li>
<li><a href="/rooms/terrace" aria-current="page">Terrace Room</a></li>
</ol>
</nav>
Meaning: A breadcrumb shows the path from Home to this page. <ol> (a numbered list) is used because the order means something: from Home, down to Rooms, then to the Terrace Room. The last link goes to this page, so that link carries aria-current="page".
⚡ What's hidden gets used less
Guess first: four links are hidden behind a "Menu" button to keep things tidy. Do guests use the navigation as often as when the links are visible?
No. A 2016 study by NN/g (a UX research company): on phones, hidden navigation was used in 57% of cases, while partly visible navigation was used in 86%.
Meaning: Four short links fit in one row on a 375px phone, so just show them. A bottom tab bar (a row of buttons at the bottom of the screen) suits 3 to 5 app destinations. A hamburger (a menu behind one button) is only for links that don't fit and are rarely looked for.