Sub topic 17
Testing navigation and footers
This chapter assumes you can write the markup from earlier chapters: a nav landmark with a list of links, a skip link, aria-current, a disclosure-button mega menu, and a footer with a labeled nav. It also assumes you know basic JavaScript event handling and media queries. The goal here is to check that all of it works for keyboard users, screen reader users, and people on touch screens.
Why navigation needs its own test pass
Navigation appears on every page. A defect in it is repeated on every page and blocks access to everything else. Automated tools catch only part of the problems, so a reliable test plan combines three layers:
- Automated checks for missing names, bad ARIA, and low contrast.
- Manual keyboard testing.
- Screen reader and touch testing.
Run the layers in that order. Each one finds problems the earlier one cannot.
Automated checks
Automated tools find structural errors quickly. They cannot judge whether a label makes sense or whether focus moves in a sensible order.
An automated scan can catch:
- A
navwithout an accessible name when the page has more than one. aria-controlsthat points to an id that does not exist.- Invalid ARIA attribute values.
- Links with no text.
- Text and focus outlines with insufficient contrast.
- Duplicate ids.
You can also write small checks of your own. This script runs in the browser console on a page that uses the markup from earlier chapters. It reports problems that scanners often miss.
function auditNavigation() {
const problems = [];
const navs = document.querySelectorAll('nav');
if (navs.length > 1) {
const names = new Set();
navs.forEach((nav) => {
const name = nav.getAttribute('aria-label') || nav.getAttribute('aria-labelledby');
if (!name) {
problems.push('A nav landmark has no accessible name.');
} else if (names.has(name)) {
problems.push('Two nav landmarks share the name "' + name + '".');
}
names.add(name);
});
}
document.querySelectorAll('[aria-controls]').forEach((el) => {
const id = el.getAttribute('aria-controls');
if (!document.getElementById(id)) {
problems.push('aria-controls points to a missing id: ' + id);
}
});
document.querySelectorAll('[aria-expanded]').forEach((el) => {
const value = el.getAttribute('aria-expanded');
if (value !== 'true' && value !== 'false') {
problems.push('aria-expanded has an invalid value: ' + value);
}
});
const current = document.querySelectorAll('nav [aria-current="page"]');
if (current.length > 1) {
problems.push('More than one link is marked as the current page.');
}
const skip = document.querySelector('.skip-link');
if (!skip) {
problems.push('No skip link found.');
} else if (!document.querySelector(skip.getAttribute('href'))) {
problems.push('The skip link target does not exist.');
}
return problems;
}
console.log(auditNavigation());An empty array means none of these checks failed. It does not mean the navigation is accessible.
Keyboard testing
Put the mouse aside and use only the keyboard. This is the most valuable manual test, and it takes a few minutes.
Reload the page and press Tab once. Then work through this checklist.
| Check | Expected result |
|---|---|
| First Tab press | Focus lands on the skip link, and it becomes visible. |
| Enter on the skip link | Focus moves into the main content, so the next Tab goes to the first control in `main`. |
| Tab through the header | Focus visits each link and button in reading order, with no traps. |
| Focus indicator | Every focused item has a clearly visible outline. |
| Enter or Space on a menu button | The panel opens and `aria-expanded` becomes `true`. |
| Tab after opening a panel | Focus moves into the first link of the panel. |
| Escape inside a panel | The panel closes and focus returns to its button. |
| Shift+Tab | Focus moves backward through the same order. |
| Tab into the footer | Every footer link is reachable and focus is visible. |
Common keyboard failures
- The skip link never appears. The CSS may hide it with
display: noneinstead of moving it off-screen, so it cannot receive focus. - The skip link moves the view but not focus. In some browsers, a target that is not focusable keeps the old focus position. Adding
tabindex="-1"to the target element fixes this. - A menu opens on hover only. Keyboard users never trigger hover, so the panel is unreachable.
- Focus disappears. A panel that closes while it contains the focused element leaves focus on nothing. Return focus to the trigger button.
- The outline is removed. A rule such as
outline: nonewith no replacement hides focus. Use:focus-visibleto style it instead.
Screen reader testing
Test with at least one real screen reader. Common pairings are NVDA with Firefox or Chrome on Windows, VoiceOver with Safari on macOS and iOS, and TalkBack with Chrome on Android. Results differ between them, so a single pass is a spot check and not a guarantee.
Listen for these things:
- Landmarks. Open the landmark list in your screen reader. You should see "Primary navigation" and "Footer navigation" as separate entries, plus the main region and the footer. Both names should be distinct.
- Link names. Open the list of links. Each link should make sense out of context. Several links that all read "Learn more" fail this check.
- Buttons. A menu button should be announced with its name and its state, for example "Products, button, collapsed". After activation it should say "expanded".
- Current page. The current link should be announced as "current page" or similar.
- Headings. In the footer, each group should have a heading, and the heading level should fit the page outline.
Touch, zoom, and responsive testing
Many navigation failures appear only at small widths or high zoom.
- Target size. Use a real phone or device emulation. Links and buttons should be easy to hit without touching a neighbor. Aim for at least 44 by 44 CSS pixels, and never fall below 24 by 24 (the WCAG 2.2 minimum).
- Zoom to 200 percent. The navigation should still work and nothing should be cut off.
- Reflow at 320 CSS pixels wide. This is equivalent to 400 percent zoom on a 1280 pixel window. Content should reflow into one column without horizontal scrolling.
- Text spacing. Increase text size in the browser settings. Menu labels should wrap or the layout should adapt, not overlap.
- Orientation. Rotate a device. The menu should work in both orientations.
- Hover-only behavior. On touch devices, hover does not exist. A first tap must open a panel, and a second tap must follow a link.
- Collapsed menu button. At narrow widths, the menu toggle must have the same keyboard behavior as a desktop submenu button.
A regression checklist
Run these checks whenever the navigation or footer changes. A short written list is easier to repeat than memory.
<ul>
<li>Skip link appears on first Tab and moves focus to main.</li>
<li>Exactly one link has aria-current="page".</li>
<li>Each nav landmark has a unique accessible name.</li>
<li>Menu buttons toggle aria-expanded and respond to Enter, Space, and Escape.</li>
<li>Focus is visible on every link and button.</li>
<li>Navigation works at 320 px wide and at 200 percent zoom.</li>
<li>Touch targets are at least 24 by 24 CSS pixels.</li>
<li>Footer links are grouped under headings and reachable by keyboard.</li>
<li>A screen reader lists both navigation landmarks and the footer.</li>
</ul>Testing the footer specifically
The footer is easy to forget because it sits at the end of the page. Check these points:
- Keyboard users can reach it with Tab, or jump to it with a screen reader landmark command.
- The
footerelement sits directly underbody, which gives it the contentinfo landmark role. Afooternested insidemainorarticledoes not. - The footer
navhas its own label, such as "Footer", so it is distinct from "Primary". - Link text meets contrast requirements. Small gray text on a dark background is a frequent failure.
- Footer links are not so close together that touch users hit the wrong one.
- Links such as Privacy policy and Contact lead to real pages and are not broken.
Exercise
You test a mega menu with the keyboard. Pressing Enter on the "Products" button opens the panel, but pressing Escape closes it and focus moves to the top of the page. What is wrong, and what should happen instead?
Show answer
The Escape handler hides the panel without moving focus, so the focused element disappears and the browser resets focus. After closing the panel, the script should call focus() on the "Products" button, so the user stays where they were and can reopen the menu or tab onward.
Exercise
An automated scan reports no errors on your page, which has a header navigation and a footer navigation that both use aria-label="Navigation". Why is this still a problem, and how do you fix it?
Show answer
Two landmarks with the same name cannot be told apart in a screen reader's landmark list. Give each one a distinct label, such as aria-label="Primary" on the header nav and aria-label="Footer" on the footer nav.