Workbench / Volume 2 Companion: The Web Frontend
V2·20
Accessibility
Companion to Volume 2, chapter 20: how foundations, perceiving and operating, and ARIA connect; new angles (the accessibility tree as a radio script, focus as a cursor someone else is holding, live regions as the station announcer, ARIA as stage directions an actor can't perform); what the chapter simplifies, measured in Chromium's own accessibility tree: a performance trick (`content-visibility: auto`) that leaves 285 of 300 orders without content for screen readers, CSS-generated text that is part of names ("Late:", "→", "★"), and a disabled button that throws keyboard focus back to the page; the theory behind it; how `dom-accessibility-api` (behind Testing Library's `getByRole`) computes names, and the two ways it disagrees with the browser; four debugging drills; interview questions with how to approach each.
Understanding it better
Concept map
Chapter 20 has three strands. Foundations: who accessibility serves and WCAG's four principles, semantic HTML, accessible names and descriptions, keyboard navigation, focus management and target size. Perceiving and operating: screen readers and the accessibility tree, contrast, zoom and reflow, motion and flashing, status messages. ARIA, widgets and testing: roles, states and properties, live regions, the dialog, tabs and combobox patterns, and testing with tools and people.
The links worth remembering:
- The accessibility tree is the product for assistive technology. Screen readers, voice control and switch devices don't see pixels or the DOM; they see the tree the browser builds from your HTML, CSS and ARIA. Anything that changes the tree (CSS included) changes the product for them (Gaps 1 and 2).
- Focus is shared state. A keyboard or screen-reader user's position on the page is
document.activeElement. Code that removes, disables or re-renders the focused element moves them without asking (Gaps 3). - ARIA changes what's announced, never what happens. It adds semantics HTML can't express; the behaviour (keyboard, focus) is always your code's job.
Explain it differently
1. The accessibility tree is the radio script of your page. A sighted user watches the broadcast; a screen-reader user listens to a script the browser writes from your markup: "heading level 2, Order o12; list, 3 items; button, Accept". If something isn't in the script, it isn't on the radio, however good it looks on screen (Gaps 1).
2. Focus is a cursor someone else is holding. For a keyboard user, focus is where they are. Moving it is like moving someone's place in a book while they read: occasionally necessary (opening a dialog), always announced, never accidental (Gaps 3).
3. Live regions are the station announcer. Most changes on a page happen silently for a screen-reader user unless an announcer says them. role="status" is the polite announcer who waits for a pause; role="alert" interrupts. An announcer who talks constantly is turned off (users mute busy regions), so announce what matters, once.
4. ARIA is stage directions an actor can't perform. role="button" on a div tells the audience "this is a button", but the actor still has to respond to Enter and Space, take focus, and look pressed. Native elements come with the performance included.
5. WCAG's POUR is a checklist for a door. Perceivable: can you see (or hear, or feel) that there's a door? Operable: can you open it with whatever you have? Understandable: is it clear what's behind it? Robust: does it still work with a different key?
6. Contrast and target size are the physics of reading and pointing. A 4.5:1 ratio is the difference between reading in daylight and squinting at dusk; a 24 px target is the difference between a big lift button and a pinhole. Both are measured, and both matter for everyone with tired eyes, a cracked screen or a moving bus.
7. Hidden has three meanings. Hidden from everyone (display: none, hidden), hidden from sight but heard (a visually hidden class), and seen but not heard (aria-hidden="true"). Mixing them up creates ghosts (focusable things that can't be seen) or silent content (Chapter Exercises P4).
8. Automated tools are a spell checker. They catch missing labels, low contrast and invalid ARIA quickly; they can't tell you whether the page makes sense. "No axe errors" is like "no spelling mistakes": necessary, nowhere near sufficient.
Gaps and misconceptions
What the chapter oversimplifies
All outputs are real, from Chromium 153's own accessibility tree, read through the DevTools protocol (Accessibility.getFullAXTree, queryAXTree), which is the tree platform screen readers are given.
1. Performance features change the accessibility tree: content-visibility: auto. Stage 18 of the TiffinBox build put content-visibility: auto on order cards to skip rendering off-screen ones. The same 300 cards, with and without it:
content-visibility none : full tree headings 300, after 2 s 300 | aria snapshot headings 300 | queryAXTree(role=heading) 300
content-visibility auto : full tree headings 15, after 2 s 15 | aria snapshot headings 300 | queryAXTree(role=heading) 15
All 300 list items stay in Chromium's tree, but the 285 off-screen ones have no content: no heading, no text. A screen-reader user listing headings finds 15 orders, and moving through the list reaches empty items. Playwright's aria_snapshot() reports 300, because it computes its own view from the DOM, not the browser's tree, so an accessibility test based on it would pass. Rendering skipped is accessibility skipped: measure with the browser's tree (as here), and prefer contain: content or virtualisation designed with assistive technology in mind (drill D1). Stage 20 of the build removes it from the display.
2. CSS-generated content is part of the accessible name. The chapter treats names as coming from content, labels and ARIA. Text added with ::before/::after is content too:
- list:
- listitem:
- paragraph: "Late: waiting 12 min"
- paragraph: ★Masala dosa
- paragraph: "Popular: Masala dosa"
- link "Menu →":
- /url: /menu
The display's red "Late:" prefix (stage 17, added with content: "Late: ") is announced, which is what we want: the state isn't conveyed by colour alone. But a decorative arrow becomes part of the link's name ("Menu right arrow" in a screen reader), and a star icon is read as "black star". CSS has alternative text for generated content: content: "★" / "Popular: " is announced as "Popular:", and content: "→" / "" is silent. Decorative generated content needs the empty alternative (drill D2).
3. Disabling the focused button sends keyboard focus to the page. The stage 17 display disables a button while its request runs (to prevent double taps). What happens to a keyboard user who just pressed it:
focused button, then disabled = true -> focus on: BODY | Tab goes to: b
focused button, then aria-disabled='true' -> focus on: b | Tab goes to: c
A disabled button can't hold focus, so document.activeElement becomes <body>: a screen reader announces the page (or nothing), and the user has lost their place on a page of 200 cards. (Chromium remembers where focus was for the next Tab, but the announcement and any keyboard shortcut handlers are lost.) aria-disabled="true" keeps focus and tells assistive technology the button is unavailable; the code must then ignore clicks itself (drill D3).
Common misconceptions
| Misconception | What's actually true | Where it's shown |
|---|---|---|
| "Performance CSS doesn't affect accessibility." | content-visibility: auto leaves off-screen content out of Chromium's tree. |
Gaps 1; drill D1 |
| "Decorative CSS content is ignored by screen readers." | It's part of the name unless given an empty alternative (content: "→" / ""). |
Gaps 2; drill D2 |
| "Disabling a button during a request is harmless." | It drops keyboard focus; use aria-disabled and ignore repeat clicks. |
Gaps 3; drill D3 |
| "Our tests check names, so they match the browser." | Test libraries compute names themselves and can disagree with the browser. | Code walkthrough; drill D4 |
| "An aria snapshot is the accessibility tree." | Playwright's snapshot is computed from the DOM; the browser's tree can differ. | Gaps 1 |
| "Accessibility overlays fix compliance." | They don't fix the underlying markup and often interfere with users' own tools. | Interview Q5 |
Theoretical gaps: the ideas behind the chapter
1. Accessibility is an interface contract between three parties. The author writes HTML, CSS and ARIA; the browser computes roles, names, states and relationships (the accessibility tree) and exposes them through platform APIs (UIA on Windows, AX on macOS, AT-SPI on Linux); assistive technology presents them. Bugs live at each boundary: author mistakes, browser differences (WebKit, Blink and Gecko compute some names differently) and screen-reader behaviour. Testing in one place checks one boundary.
2. The accessible name computation is a specified algorithm. "Accessible Name and Description Computation" (accname) is a W3C recursive algorithm over the tree: aria-labelledby, aria-label, native labels, then content (including CSS generated content), with rules about hidden nodes and embedded controls. Its edge cases are why test libraries and browsers disagree (Code walkthrough), and why the web-platform-tests suite has hundreds of name tests.
3. Disability is a mismatch, not a property of a person. The social model of disability says people are disabled by environments that don't fit them. It's why accessibility helps far more people than any medical definition suggests (situational and temporary disabilities: a broken arm, glare, a noisy kitchen) and why accessible design is good design, not a special mode.
4. Equivalence over identity. WCAG asks for equivalent experiences, not identical ones: a screen-reader user doesn't need the animation, they need the information it conveys ("Order o12 is late"), at the moment it matters. Designing the non-visual experience explicitly (what's announced, in what order, how often) is part of designing the feature.
5. Robustness means working with tools you didn't test. The "R" in POUR is about future and unknown user agents: using standard semantics means voice control, braille displays, switch access and screen magnifiers all work, including ones you've never tried. Custom widgets with ARIA work only to the extent every tool implements those patterns.
6. Legal frameworks are converging on WCAG. The European Accessibility Act (in force from June 2025) requires many consumer digital services to be accessible, using EN 301 549, which references WCAG 2.1 AA; India's Rights of Persons with Disabilities Act 2016 and the GIGW guidelines do the same for government and increasingly private services; the US ADA is applied to websites through court cases. Conformance reporting (accessibility statements, VPATs) is how organisations document where they stand.
Applying it
Code walkthrough
Testing Library's getByRole('button', { name: 'Accept' }), used in most React and Angular test suites, finds elements by their accessible name computed by dom-accessibility-api. Excerpts from version 0.7.0, dist/accessible-name-and-description.mjs, installed from npm.
Text from the subtree, including pseudo-elements
// 2F.i
function computeMiscTextAlternative(node, context) {
var accumulatedText = "";
if (isElement(node) && computedStyleSupportsPseudoElements) {
var pseudoBefore = uncachedGetComputedStyle(node, "::before");
var beforeContent = getTextualContent(pseudoBefore);
accumulatedText = "".concat(beforeContent, " ").concat(accumulatedText);
}
// FIXME: Including aria-owns is not defined in the spec
// But it is required in the web-platform-test
var childNodes = isHTMLSlotElement(node) ? getSlotContents(node) : ArrayFrom(node.childNodes).concat(queryIdRefs(node, "aria-owns"));
childNodes.forEach(function (child) {
var result = computeTextAlternative(child, {
isEmbeddedInLabel: context.isEmbeddedInLabel,
isReferenced: false,
recursion: true
});
// TODO: Unclear why display affects delimiter
// see https://github.com/w3c/accname/issues/3
var display = isElement(child) ? getComputedStyle(child).getPropertyValue("display") : "inline";
var separator = display !== "inline" ? " " : "";
// trailing separator for wpt tests
accumulatedText += "".concat(separator).concat(result).concat(separator);
});
This is step 2F of accname ("name from content"): the ::before text, then each child's text alternative computed recursively, then ::after. The comments are a record of the specification's unsettled corners: aria-owns isn't in the spec but the shared tests require it; whether block-level children add spaces is an open issue (accname #3). Notice the guard: pseudo-elements are read only when computedStyleSupportsPseudoElements is true, and the option's default is options.getComputedStyle !== undefined: only when the caller passes its own getComputedStyle. Test environments like jsdom don't support pseudo-elements, so the default is off.
Reading content
function getTextualContent(declaration) {
var content = declaration.getPropertyValue("content");
if (/^["'].*["']$/.test(content)) {
return content.slice(1, -1);
}
return "";
}
The computed content value is a quoted string, so the function strips the first and last character. That's correct for "Late: " and wrong for the alternative-text syntax, whose computed value is "★" / "Popular: ": it also starts and ends with a quote.
Read it yourself
- Compute the names of five buttons with generated content, in Chromium and with the library (default options, and with pseudo-elements on). Where do they differ?
- Why would a library default to ignoring pseudo-elements, and what does that mean for a test that passes?
Debugging drills
D1. "The display only shows a few orders", says a blind cook
A screen-reader user at a kitchen that adopted the display reports that the "list headings" command finds 12 orders when the screen shows "52 open orders", and that moving down the list reaches items that say nothing. Sighted staff see every card. Axe reports no violations; the team's Playwright test (aria_snapshot) lists all 52 headings.
D2. "Menu right arrow, link", "Black star, Masala dosa, button"
Screen-reader users report odd names on links and buttons since a design refresh. The refresh replaced icon images (which had alt="") with CSS: .next::after { content: "→"; } and .popular::before { content: "★"; }.
D3. Keyboard users "lose their place" after accepting an order
On the kitchen display, a keyboard user tabs to "Accept" on the third card and presses Enter. The order is accepted, but the next Tab doesn't go to "Ready" on that card, and their screen reader says "TiffinBox, web content". The code sets button.disabled = true while the request runs.
D4. A test fails after a refactor that changed nothing users hear
A styling refactor moved the "Late:" prefix on order cards from markup (<strong>Late:</strong> waiting 12 min) into CSS (.late .age::before { content: "Late: "; }). The component test getByText still finds the card, but getByRole('paragraph', { name: 'Late: waiting 12 min' })-style assertions (and an accessibility snapshot test) now fail in jsdom. A developer proposes changing the expected name to "waiting 12 min".
Career-oriented
Interview prep
Mid level
Q1. A list of orders updates live. How do you make updates accessible without overwhelming screen-reader users?
How to get there. Decide what deserves an announcement (new orders? every status change? late orders?), how (one polite live region, not the list), how often (batching), and how users can get details on demand (the list itself, with good headings).
Q2. What's wrong with <div class="card" onclick="open(12)" tabindex="0">, beyond what axe reports?
How to get there. List what a keyboard and screen-reader user experiences: role, name, activation keys, focus visibility, nested interactive content. Then give the fix.
Senior level
Q3. Design accessibility testing for TiffinBox so that problems like Gaps 1–3 are caught before release.
How to get there. Chapter Exercises C2 designs a test strategy; focus on the gaps automated tools miss: the browser's actual tree, focus behaviour over time, and announcements. Decide what's automated and what needs people.
Q4. A performance optimisation (virtualising a 2,000-row table) is ready to merge. What accessibility questions do you ask?
How to get there. Think about what virtualisation removes from the DOM and therefore from the tree, and what users of each assistive technology rely on: counts, navigation by row and heading, find-in-page, and focus stability while scrolling.
Staff level
Q5. A vendor offers an "accessibility overlay" that promises WCAG compliance with one script tag. Leadership likes the price. What's your recommendation?
How to get there. Chapter Exercises leaves overlays out. Separate the claims (automatic fixes, compliance, legal protection) from what such scripts can do, consider users' own assistive technology, and offer an alternative plan with costs.
Q6. TiffinBox will be sold to institutional kitchens (hospitals, universities) whose procurement asks for a conformance report. How do you produce one that's honest and useful?
How to get there. Chapter Exercises leaves conformance reporting out. Decide scope (which pages and flows), method (tools plus manual testing with assistive technology), format (a VPAT/ACR based on WCAG 2.2 AA or EN 301 549), and what to do about known gaps.