Testing HTML Accessibility
What automated checkers like axe catch and miss, how to test by keyboard and screen reader, and how to read the browser's accessibility tree.
Testing HTML Accessibility
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Automated tools find the mechanical failures: missing names, missing alt, low contrast, bad heading order. They cannot judge whether a page makes sense.
- In a test, axe-core 4.10.3 reported nine rule violations on a small bad page, but said nothing about a clickable `div` pretending to be a button or a `role="button"` with no keyboard support.
- A keyboard pass is the cheapest manual test: unplug the mouse, press Tab, and check that you can reach, see and operate everything in a sensible order.
- The browser's accessibility tree is ground truth for what assistive technology gets. Use DevTools, and be wary of text snapshots from test libraries that approximate it.
- The HTML validator catches broken nesting, duplicate ids and missing `alt`, which are accessibility bugs too. It is a separate check from axe.
Why tests come in layers
A smoke detector checks for smoke, not whether the building is safe. Accessibility checks work the same way, and no single tool covers the field. Three layers are worth knowing: an automated rule engine, your own keyboard, and a screen reader. A fourth, the markup validator, finds broken structure.
What automation catches
I built a small page with a dozen deliberate problems and ran axe-core 4.10.3 on it in Chromium. It reported these violations: an unlabelled icon button (button-name), an image with no alt, a link with no text, low-contrast text, a skipped heading level, a missing lang on html, a focusable element inside aria-hidden, plus page-level landmark-one-main and region. All real, all mechanical.
It said nothing about two others in the same file. A <div onclick> styled as a button was invisible to it, because from the tree’s point of view it is just a div. And a <div role="button"> with no tabindex passed, since the role was valid and no rule asked whether the keyboard could operate it. Both are failures you saw in keyboard focus. The lesson is that axe finds what it can prove, and silence is not approval.
Test with the keyboard
This costs nothing. Use Tab and Shift+Tab to move, Enter and Space to activate, Escape to close, arrow keys inside widgets. Check:
- Can you reach every control, and nothing extra?
- Is the focus ring always visible (focus styles)?
- Does the order match the visual flow?
- Can you leave every menu and dialog?
Test with a screen reader
Use the one your platform ships: VoiceOver on macOS, NVDA or Narrator on Windows. You aren’t trying to be an expert user; you are listening for controls with no name, headings that aren’t headings, and announcements that lie. I did not run a screen reader for this lesson, so I make no claims about what any of them says.
Read the tree, not the approximation
DevTools’ Accessibility pane shows the role, name and description the browser computed, which is what names and descriptions described. Be careful with text dumps from test libraries. In a test, Playwright’s ariaSnapshot() listed buttons inside an inert container that Chromium’s own tree had dropped. Handy for regression tests, wrong as a source of truth.
Validate the markup
The Nu HTML Checker (vnu.jar, version 26.11.20 in my run) flagged these in a short file: a div inside a span, a stray </p> after a div inside a p, a button inside an a, an img with no alt, a duplicate id, a div inside a ul, an obsolete center element, a missing lang, and a skipped heading level. It did not flag the role="button" div or a positive tabindex. See validation and debugging.
What the video covers
Adrián Bolonio’s “Testing Web Accessibility” at JSConf (June 2022, about 30 minutes). The description frames it as how automated accessibility tests and manual tests together can improve an interface for people with disabilities. I could not read a transcript, so I cannot list its tools or demos. The axe, tree and validator results are my own runs on a synthetic page, and tool versions will have moved on since the talk.
Where this fits
This ends the accessibility group. The interactive elements come next, starting with details and summary, and you can test each one with these techniques.
Check yourself
Your page scores 100 in an automated audit. Can you ship it as accessible?
No. Automated rules cover a minority of problems. In a test axe flagged names, alt, contrast and headings but missed a clickable `div` with no role and a `role="button"` that ignored Enter and Space. A keyboard pass and a screen reader pass find those.
What is a fast manual test you can do with no tools?
Put the mouse aside and use Tab, Shift+Tab, Enter, Space and Escape. Check that every control is reachable, that focus is visible and in a sensible order, that nothing traps you, and that dialogs and menus can be closed.
Why compare a test library's text snapshot of the page with DevTools?
The snapshot is the library's approximation. Playwright's `ariaSnapshot` listed buttons inside an `inert` container that the real Chromium accessibility tree had removed. DevTools shows what the browser computed.
What would the Nu HTML Checker find that axe does not?
Structural errors in the markup: a `div` inside a `span`, a stray `</p>`, a `button` inside a link, an `ul` with a `div` child, duplicate ids, obsolete elements. Several of these confuse assistive technology.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.