FE·20
Accessibility
Building interfaces everyone can use: WCAG and POUR, semantics and accessible names, keyboard and focus, screen readers, contrast, reflow, zoom and motion, ARIA roles, states, properties and live regions, and the standard widget patterns.
Start here: building for everyone
Who accessibility is for
Web accessibility means people can perceive, understand, navigate and use a site whatever their abilities and circumstances. About one in six people worldwide lives with a significant disability (WHO, 2023), and many more have a temporary or situational one:
| Permanent | Temporary | Situational | |
|---|---|---|---|
| Seeing | blind, low vision, colour-blind | eye surgery, lost glasses | bright sunlight on a phone |
| Hearing | deaf, hard of hearing | ear infection | a noisy train, a sleeping baby |
| Moving | paralysis, tremor, missing limb | broken arm | holding a child in one arm |
| Thinking | dyslexia, ADHD, memory impairment | concussion, medication | stress, distraction, a second language |
Accessibility is also a legal requirement in many places (the European Accessibility Act has applied to many consumer services since June 2025; India's Rights of Persons with Disabilities Act and its guidelines cover government and many public-facing services; the ADA in the US), and accessible sites are better for everyone: clearer structure, better search ranking, keyboard shortcuts, readable contrast in sunlight.
How people actually use the web
- Screen readers (NVDA and JAWS on Windows, VoiceOver on Apple devices, TalkBack on Android) read the page aloud or to a braille display. Users navigate by headings, landmarks, links and form fields, jumping rather than listening to everything. They depend on the accessibility tree (chapter 12) that the browser builds from your HTML.
- Keyboard-only users press Tab to move between interactive elements, Shift+Tab to go back, Enter to follow links and press buttons, Space for buttons and checkboxes, arrow keys inside widgets, and Escape to close things. They need to see where focus is.
- Zoom and magnification users enlarge text to 200% or the whole page to 400%. Layouts must reflow without sideways scrolling.
- Voice control users say "click Place order", so the visible label must match the accessible name.
- Switch users operate one or two buttons; everything reachable by keyboard is reachable by switch.
WCAG and its four principles
The Web Content Accessibility Guidelines (WCAG, currently 2.2, from the W3C) are the standard that laws reference. Level AA is the usual target. Its success criteria are grouped under four principles, POUR:
- Perceivable: information can be seen or heard by everyone: text alternatives for images, captions for video, sufficient contrast, content that adapts to zoom.
- Operable: everything works with a keyboard, users have enough time, nothing flashes dangerously, navigation is clear, targets are big enough.
- Understandable: text is readable, behaviour is predictable, forms help users avoid and fix mistakes.
- Robust: it works with assistive technology, which mostly means correct HTML semantics and names.
Six fixes that solve most problems
Here's a lunch-order page as many sites build it, and what axe reports:
<html>
<head><title>Order</title><style>.hint{color:#aaa} .cta{background:#f5a623;color:#fff;padding:8px} :focus{outline:none}</style></head>
<body>
<div class="logo"><img src="logo.png"></div>
<div style="font-size:28px;font-weight:bold">Order lunch</div>
<p class="hint">Delivery in 30 minutes</p>
<input type="text" placeholder="Your name">
<input type="tel" placeholder="Phone">
<div class="cta" onclick="placeOrder()">Place order</div>
<a href="/menu"><img src="menu-icon.svg"></a>
</body>
</html>
bad.html: 7 rule(s) violated
serious color-contrast (2): Elements must meet minimum color contrast ratio thresholds
serious html-has-lang (1): <html> element must have a lang attribute
critical image-alt (2): Images must have alternative text
moderate landmark-one-main (1): Document should have one main landmark
serious link-name (1): Links must have discernible text
moderate page-has-heading-one (1): Page should contain a level-one heading
moderate region (7): All page content should be contained by landmarks
And what a screen reader user gets (the accessibility tree):
- img
- text: Order lunch
- paragraph: Delivery in 30 minutes
- textbox "Your name"
- textbox "Phone"
- text: Place order
- link:
- img
An unlabelled image, a "heading" that's just text, a "button" that's just text (and can't be reached with Tab, chapter 13), and a link announced as "link, image" with no idea where it goes. The six fixes:
- Give images text alternatives:
alt="Sharma's Tiffin home"on the logo link's image;alt=""on decorative ones. - Use real structure:
<html lang="en">, a real<h1>,<header>and<main>landmarks. - Label every form field with a
<label>(placeholders vanish when typing and aren't reliable names). - Use real controls:
<button>for actions,<a href>with text for navigation. - Meet contrast: at least 4.5:1 for normal text and 3:1 for large text and UI components. The light grey hint is 2.32:1 and white on that orange is 2.03:1 (both fail);
#595959grey is 7.00:1 and white on#8a4b08brown is 6.79:1. - Never remove focus outlines without a clearly visible replacement (
:focus-visible { outline: 3px solid #1a5fb4; }).
The fixed page (<html lang="en">, <header>, <main>, <h1>, labelled inputs with autocomplete, a <button>, alt text, darker colours, a focus style) gets:
good.html: 0 rule(s) violated
- banner:
- link "Sharma's Tiffin home"
- main:
- heading "Order lunch" [level=1]
- paragraph: Delivery in 30 minutes
- textbox "Your name"
- textbox "Phone"
- button "Place order"
- link "Full menu"
Automated tools catch only part of it
Zero axe violations doesn't mean accessible. On the bad page, axe didn't report the clickable <div> (unreachable by keyboard), the removed focus outline, or the placeholder-only fields (it accepted the placeholders as names). Automated checkers find somewhere between a third and a half of real-world issues (estimates vary with how you count); the rest need a human. A five-minute manual check catches most of what's left:
- Unplug your mouse. Tab through the page. Can you reach and operate everything? Can you always see where you are? Does focus move in a sensible order and never get stuck?
- Zoom to 200%, then 400%. Does text stay readable without sideways scrolling?
- Turn on a screen reader (VoiceOver: Cmd+F5 on a Mac; NVDA is free on Windows) and use its heading list. Does the page make sense from headings alone? Do buttons and links say what they do?
- Check the DevTools Accessibility pane for one element: its role, name and states.
ARIA, in one rule
ARIA (Accessible Rich Internet Applications) is a set of attributes (role, aria-label, aria-expanded, aria-live and more) that change what the accessibility tree says about an element. It's essential for custom widgets (tabs, comboboxes, tree views) that have no native HTML element. But it only changes what's announced, never what the element does: <div role="button"> is announced as a button but still can't be focused or pressed with the keyboard until you add tabindex and key handlers yourself. Hence the first rule of ARIA: if a native element does the job (<button>, <a>, <input>, <dialog>, <details>), use it instead.
How deep to go in accessibility
Volume 17 defines six mastery levels. For this chapter they look like this; the chapter aims at L3 everywhere, and its lab at L4.
| Level | What you can do |
|---|---|
| L1 | Explain who accessibility serves, POUR, and the common failures |
| L2 | Build pages and forms that pass automated checks, keyboard tests and contrast rules |
| L3 | Explain accessible names, roles and states, focus management, live regions and the ARIA patterns for common widgets |
| L4 | Audit with screen readers, keyboard and zoom; diagnose name, focus and announcement bugs |
| L5 | Design accessible components and design-system rules; choose native elements vs custom widgets |
| L6 | Run an accessibility programme: CI checks, audits, VPAT/ACR documentation, legal compliance, user testing |
Why and what
Who accessibility serves
Accessibility (a11y) means people with disabilities can perceive, understand, navigate and interact with your product. About 1 in 6 people worldwide has a significant disability (WHO), and far more have temporary or situational limitations: a broken arm, glare on a phone screen, a noisy train, a slow connection, ageing eyesight.
| Disability | Examples | What they rely on |
|---|---|---|
| Visual | Blindness, low vision, colour blindness | Screen readers, magnification and zoom, high contrast, not relying on colour alone |
| Motor | Tremor, paralysis, RSI, limb difference | Keyboard only, switch devices, voice control, large targets, no time limits |
| Auditory | Deafness, hard of hearing | Captions, transcripts, visual alternatives to sounds |
| Cognitive / learning | Dyslexia, ADHD, memory impairments, autism | Clear language, consistent navigation, predictable behaviour, error help, no distractions |
| Vestibular / seizure | Motion sensitivity, photosensitive epilepsy | Reduced motion, no flashing (more than 3 flashes per second) |
There are also legal reasons: the EU's European Accessibility Act has applied to many consumer digital products and services since June 2025, the US ADA and Section 508, India's Rights of Persons with Disabilities Act and the GIGW guidelines, and similar laws elsewhere. Most of them point to WCAG 2.1 or 2.2 Level AA. Accessible sites also tend to have better SEO, better automated testability (Playwright's role queries, chapter 26), and better usability for everyone (the "curb-cut effect").
WCAG and POUR
The Web Content Accessibility Guidelines (W3C) are the reference standard. WCAG 2.2 (2023) is current. WCAG 3 is a long-term draft with a different scoring model. WCAG has three conformance levels: A (minimum), AA (the usual legal and contractual target) and AAA (enhanced). Its success criteria sit under four principles, POUR:
| Principle | Meaning | Example criteria |
|---|---|---|
| Perceivable | Information can be perceived by some sense | 1.1.1 text alternatives (alt text) · 1.2.x captions · 1.3.1 info and relationships (semantics) · 1.3.5 input purpose (autocomplete) · 1.4.3 contrast · 1.4.4 resize text · 1.4.10 reflow · 1.4.11 non-text contrast · 1.4.12 text spacing |
| Operable | UI can be operated | 2.1.1 keyboard · 2.1.2 no keyboard trap · 2.2.x enough time · 2.3.1 three flashes · 2.4.3 focus order · 2.4.4 link purpose · 2.4.7 focus visible · 2.4.11 focus not obscured (2.2) · 2.5.7 dragging alternatives (2.2) · 2.5.8 target size minimum 24×24 CSS px (2.2) |
| Understandable | Information and operation are understandable | 3.1.1 page language · 3.2.x predictable (no unexpected context changes) · 3.3.1 error identification · 3.3.2 labels · 3.3.7 redundant entry · 3.3.8 accessible authentication (2.2: no cognitive tests like puzzles; allow paste and password managers) |
| Robust | Works with current and future assistive tech | 4.1.2 name, role, value · 4.1.3 status messages (live regions) |
Accessibility is a design and engineering discipline, not a final audit. It's cheapest when designers specify focus states, contrast, labels and error flows, and engineers use semantic components from the start.
Semantics and names
Semantic HTML first
Chapter 13 covered semantic HTML. The short version: native elements give you role, name, state, keyboard behaviour and focus management for free. The most reliable way to build an accessible app is to use <button>, <a href>, <label> + <input>, <select>, <dialog>, <details>, headings, lists, tables and landmarks correctly, and only then add ARIA where native HTML has no equivalent.
Native semantics first; ARIA only when required. No ARIA is better than bad ARIA. WebAIM's yearly survey of the top million home pages consistently finds that pages with ARIA have more detected errors than pages without it.
Accessible names
Every interactive element, and many others, needs an accessible name, which is what assistive technology announces: "Save, button", "Email, edit text, required". The name is computed by the Accessible Name and Description Computation spec (accname), in roughly this priority order:
aria-labelledby(references other elements' text by ID; can combine several).aria-label(a string).- Native labelling:
<label>for form controls,altfor images,<caption>for tables,<legend>for fieldsets,titlefor iframes. - Content: the text inside the element, for roles that allow naming from content (buttons, links, headings, cells).
titleattribute, as a last-resort fallback (poor: hover-only, and inconsistently announced).
<button>Save draft</button> <!-- name from content: "Save draft" -->
<button aria-label="Close dialog"><svg aria-hidden="true">…</svg></button> <!-- icon-only: needs a label -->
<label for="q">Search products</label><input id="q" type="search"> <!-- name from <label> -->
<section aria-labelledby="ship-h"><h2 id="ship-h">Shipping</h2>…</section> <!-- region named by its heading -->
<a href="/orders/42">View order <span class="visually-hidden">#42 from 3 Oct</span></a>
<img src="chart.png" alt="Sales rose 40% from January to June">
Rules:
- Visible label text must be part of the accessible name (WCAG 2.5.3 Label in Name). Voice-control users say what they see: "click Send". An
aria-label="Submit form"on a button that says "Send" breaks that. - Don't duplicate role words in names ("Save button button").
- Hide decorative icons with
aria-hidden="true"so they aren't read as "image" or as gibberish. - Use a visually-hidden utility for text that screen readers need and sighted users don't. Unlike
display: none, it keeps the text in the accessibility tree:
.visually-hidden {
position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
Labels and descriptions
Labels name a control. Descriptions add supplementary information, read after the name and role:
<label for="pw">Password</label>
<input id="pw" type="password" aria-describedby="pw-hint pw-err" aria-invalid="true" required>
<p id="pw-hint">At least 12 characters, including a number.</p>
<p id="pw-err" class="error">Password is too short.</p>
<!-- Announced roughly: "Password, secure edit text, required, invalid entry. At least 12 characters…. Password is too short." -->
Group related controls with <fieldset> and <legend> (radio groups, address blocks). Show requirements before the user submits. Indicate required fields in text or with a legend explaining the asterisk, not just with colour.
Keyboard and focus
Keyboard navigation
Many people never use a mouse: screen-reader users, motor-impaired users with switches or keyboards, power users. Everything must work with a keyboard (WCAG 2.1.1). The standard model:
| Key | Action |
|---|---|
| Tab / Shift+Tab | Move to the next or previous focusable element |
| Enter | Activate links and buttons; submit forms |
| Space | Activate buttons; toggle checkboxes; scroll the page if nothing is focused |
| Arrow keys | Move within a composite widget: radio group, tabs, menu, listbox, grid, slider |
| Esc | Close dialogs, menus, popovers; cancel |
| Home / End / PageUp / PageDown | Jump within lists, grids, sliders |
Focusable by default: links with href, buttons, form controls, <summary>, <iframe>, and elements with contenteditable. tabindex changes this:
tabindex="0": add a custom element to the tab sequence, in DOM order.tabindex="-1": focusable by script (el.focus()) but not by Tab. Use it for dialog containers, headings you move focus to after navigation, and the inactive items in roving-tabindex widgets.tabindexgreater than 0: never. It creates a separate tab order that's almost impossible to maintain.
Composite widgets get one tab stop. Tab moves into the widget, arrow keys move within it, and Tab moves out. Two implementation techniques:
- Roving tabindex: the active item has
tabindex="0", the others-1. Arrow keys move the0and callfocus(). aria-activedescendant: focus stays on the container, which points to the "active" child by ID. It suits comboboxes, where focus must stay in the text input.
// Roving tabindex for a toolbar
toolbar.addEventListener("keydown", (e) => {
const items = [...toolbar.querySelectorAll("button")];
let i = items.indexOf(document.activeElement);
if (e.key === "ArrowRight") i = (i + 1) % items.length;
else if (e.key === "ArrowLeft") i = (i - 1 + items.length) % items.length;
else if (e.key === "Home") i = 0;
else if (e.key === "End") i = items.length - 1;
else return;
e.preventDefault();
items.forEach((b, j) => (b.tabIndex = j === i ? 0 : -1));
items[i].focus();
});
Skip links let keyboard users bypass repeated navigation. Make the first focusable element "Skip to main content", targeting <main id="main" tabindex="-1">. It can be visually hidden until focused.
Focus management
Focus is where keyboard input goes, and screen readers follow it. Rules:
- Visible focus (WCAG 2.4.7, and 2.4.11 not obscured in 2.2). Never remove outlines without a replacement. Style
:focus-visiblewith a clear indicator (at least 2 px, 3:1 contrast against adjacent colours) and make sure sticky headers don't cover focused elements (usescroll-padding-top). - Logical order (2.4.3): DOM order should match visual order. CSS
order,flex-direction: row-reverseand grid placement change appearance but not tab order. - Move focus deliberately when the context changes:
- Opening a dialog: focus the first meaningful control (or the dialog itself), trap focus inside while it's modal, and return focus to the trigger when it closes.
- SPA route changes: move focus to the new page's
<h1>or<main>(tabindex="-1") and announce the new title. Otherwise screen-reader users don't know the page changed, and focus may be left on a removed element, which sends it back to<body>. - Deleting an item: move focus to the next item, or to a sensible container, not into the void. - Validation errors on submit: focus the first invalid field, or an error summary. - Content loaded on demand ("Load more"): keep focus where it is, and announce the new count. - Don't move focus unexpectedly on focus or input (WCAG 3.2.1 and 3.2.2): no auto-advancing or auto-submitting when someone tabs through.
- Make background content
inertwhile a modal is open. Theinertattribute removes a subtree from focus and from the accessibility tree. Native<dialog>.showModal()does it automatically.
// Native modal dialog: focus trapping, Esc to close, inert background and top layer, all built in
const dlg = document.querySelector("#confirm");
openBtn.addEventListener("click", () => dlg.showModal());
dlg.addEventListener("close", () => openBtn.focus()); // return focus to the trigger
Target size and pointer accessibility
WCAG 2.2's 2.5.8 Target Size (Minimum) asks for interactive targets of at least 24×24 CSS pixels, or enough spacing around them. (AAA, and Apple's and Google's guidelines, recommend 44×44 or 48×48.) Other pointer criteria: anything done by dragging needs a single-pointer alternative (2.5.7: buttons as well as a sortable list's drag handle), path-based gestures need simple alternatives (2.5.1), and activation should happen on the up event so users can slide off to cancel (2.5.2). Native buttons already behave that way.
Assistive technology and visual design
Screen readers
A screen reader turns the accessibility tree into speech or braille and provides its own navigation commands:
| Screen reader | Platform | Typical browser for testing |
|---|---|---|
| NVDA (free) | Windows | Chrome, Firefox |
| JAWS | Windows | Chrome, Edge |
| VoiceOver | macOS, iOS, iPadOS | Safari |
| TalkBack | Android | Chrome |
| Narrator | Windows | Edge |
| Orca | Linux | Firefox |
Screen-reader users mostly don't Tab through everything. They jump by headings (the H key in NVDA and JAWS browse mode), landmarks (D, or the rotor on VoiceOver), links, form fields and tables, and they read line by line with the arrow keys in a virtual buffer. That's why heading structure and landmarks matter so much. In browse mode, letter keys are navigation shortcuts. In focus (forms) mode, keys go to the control. Widgets with role="application" or certain roles switch the mode, so don't use role="application" unless you implement every interaction yourself.
Learn to test with one. Turn on VoiceOver (Cmd+F5) or NVDA, close your eyes, and try to complete your app's main task. You'll find unlabelled buttons, divs pretending to be buttons, missing announcements and focus lost into the void within minutes. Automated tools (axe, Lighthouse) catch roughly 30–40% of issues. The rest need manual keyboard and screen-reader testing.
Contrast
Text must have enough contrast against its background (WCAG 1.4.3, AA):
| Content | Minimum ratio (AA) | AAA |
|---|---|---|
| Normal text | 4.5 : 1 | 7 : 1 |
| Large text (≥ 24 px, or ≥ 18.66 px bold) | 3 : 1 | 4.5 : 1 |
| UI components and graphical objects (borders of inputs, focus indicators, icons, chart lines) | 3 : 1 (1.4.11) | — |
| Disabled controls, pure decoration, logos | No requirement | — |
The ratio is (L1 + 0.05) / (L2 + 0.05) using relative luminance computed from sRGB (Vol. 1 ch. 6 covered colour representation). It ranges from 1:1 to 21:1. Check with DevTools (the colour picker shows the ratio and AA/AAA lines), axe, or the WebAIM checker. Common failures: light grey placeholder or secondary text, text over images (add an overlay or scrim), brand colours used for small text, and dark mode palettes that weren't checked separately.
Don't use colour as the only signal (1.4.1). Errors need an icon or text as well as red. Links in body text need underlines, or a 3:1 contrast with surrounding text plus a non-colour indicator on hover and focus. Chart series need patterns or direct labels. About 8% of men have some form of colour vision deficiency.
Respect user overrides: forced-colors: active (Windows High Contrast) replaces your colours with system ones. Use real borders and outlines, not just background colours, and test that icons drawn with backgrounds stay visible. prefers-contrast: more lets you offer higher contrast.
Zoom, resize and reflow
- Resize text (1.4.4): text must be scalable to 200% without loss of content or function. Use
remandem, don't fix heights on text containers, and never setuser-scalable=no. - Reflow (1.4.10): at a width of 320 CSS px (equivalent to 1280 px zoomed to 400%), content must reflow into one column without horizontal scrolling. Data tables, maps and diagrams are allowed to scroll in two dimensions. This is responsive design (chapter 14) checked by zooming the browser to 400%.
- Text spacing (1.4.12): users who override line height (1.5×), paragraph spacing (2×), letter spacing (0.12×) and word spacing (0.16×) mustn't lose content. Avoid fixed-height boxes around text.
- Orientation (1.3.4): don't lock to portrait or landscape unless it's essential.
- Content on hover or focus (1.4.13): tooltips and popovers must be dismissible (Esc), hoverable (the pointer can move onto them), and persistent until dismissed.
Reduced motion and flashing
Chapter 14 covered prefers-reduced-motion. WCAG adds: no content flashes more than three times per second (2.3.1, a seizure risk); animation triggered by interaction can be disabled (2.3.3, AAA); anything that moves, blinks or auto-updates for more than 5 seconds needs a pause, stop or hide control (2.2.2), which covers carousels, auto-playing video, tickers and animated backgrounds; and audio that plays automatically for more than 3 seconds needs a control (1.4.2).
ARIA
What ARIA is
WAI-ARIA (Accessible Rich Internet Applications) is a set of HTML attributes that change what the accessibility tree says about an element. It changes semantics only, never behaviour. role="button" makes a screen reader say "button", but it doesn't make the element focusable or keyboard-operable. You must add tabindex="0", Enter and Space handling, and the disabled state yourself. That's why <button> is almost always the better choice.
The five rules of ARIA use (W3C):
- Use native HTML elements and attributes when they exist.
- Don't change native semantics unless you really must (
<h2 role="tab">is wrong; wrap it instead). - All interactive ARIA controls must be usable with the keyboard.
- Don't use
role="presentation"oraria-hidden="true"on a focusable element. It becomes a focusable "nothing". - All interactive elements must have an accessible name.
Roles
| Category | Roles |
|---|---|
| Widget | button, link, checkbox, radio, switch, slider, spinbutton, textbox, searchbox, combobox, listbox + option, menu + menuitem (menuitemcheckbox, menuitemradio), menubar, tab + tablist + tabpanel, tree + treeitem, grid + row + gridcell, progressbar, scrollbar, tooltip |
| Document structure | heading (+ aria-level), list, listitem, table, row, cell, img, figure, article, group, separator, toolbar, none/presentation |
| Landmark | banner, navigation, main, complementary, contentinfo, region, search, form |
| Live region | alert, status, log, timer, marquee |
| Window | dialog, alertdialog |
Note that menu/menuitem mean application menus (like a desktop app's File menu), with specific arrow-key behaviour. A website's navigation links are not an ARIA menu: use <nav> with a list of links. Misusing role="menu" for site navigation is a very common error, and it changes how screen readers behave.
States and properties
States change often in response to interaction. Properties are more static. Both are aria-* attributes:
| Attribute | Meaning | Example |
|---|---|---|
aria-expanded |
Whether the controlled region is open | Disclosure buttons, accordions, comboboxes, menu buttons |
aria-controls |
IDs of the element this one controls | Button → panel |
aria-pressed |
Toggle button state (true/false/mixed) |
Bold button in an editor |
aria-checked |
Checkbox, radio, switch or menuitemcheckbox state | |
aria-selected |
Selection in tabs, listbox options, grid cells | |
aria-current |
The current item in a set (page, step, date, true) |
Current page link in the nav |
aria-disabled |
Disabled but still focusable (discoverable) | Unlike the disabled attribute, which removes focus |
aria-invalid, aria-required |
Form state | |
aria-haspopup |
The element opens a menu, listbox, dialog, grid or tree | Menu buttons, comboboxes |
aria-describedby, aria-labelledby, aria-label |
Description and name (above) | |
aria-hidden="true" |
Remove from the accessibility tree (still visible on screen) | Decorative icons |
aria-live, aria-atomic, aria-relevant, aria-busy |
Live region behaviour (next) | |
aria-modal="true" |
The dialog is modal (when not using native <dialog>) |
|
aria-activedescendant |
The focused child within a composite | Comboboxes |
aria-level, aria-posinset, aria-setsize |
Structure for trees and virtualised lists | Virtual scrolling (chapter 27) |
aria-sort |
A column header's sort direction | Sortable tables |
Keep states in sync with reality. An accordion button that says aria-expanded="false" while its panel is open misleads users. In component frameworks, derive ARIA attributes from the same state that drives the UI.
Live regions
Live regions announce dynamic changes that happen away from focus: "Saved", "3 results found", "Item added to cart", form errors after submit, chat messages, and timers. Without them, screen-reader users don't know that something changed.
<!-- The region must exist in the DOM BEFORE content is inserted into it -->
<div id="status" role="status" aria-live="polite" class="visually-hidden"></div>
<div id="alert" role="alert"></div> <!-- assertive: interrupts; use sparingly (errors) -->
function announce(msg) {
const el = document.getElementById("status");
el.textContent = ""; // clear so repeated messages are re-announced
requestAnimationFrame(() => { el.textContent = msg; }); // change content in a later frame
}
announce(`${results.length} results for “${query}”`);
| Setting | Behaviour |
|---|---|
aria-live="polite" / role="status" |
Announced when the user is idle |
aria-live="assertive" / role="alert" |
Interrupts immediately (errors, urgent warnings) |
role="log" |
Polite, for new entries appended to a log (chat) |
aria-atomic="true" |
Read the whole region, not just the changed part |
aria-busy="true" |
Suppress announcements while the region is updating |
Common mistakes: adding the live region at the same time as its content (it isn't announced), making whole sections live (everything inside gets read), making everything assertive, and relying on toasts that disappear too fast and can't be reached by keyboard.
Widget patterns
The ARIA Authoring Practices Guide (APG) documents the expected roles, states and keyboard behaviour for common widgets. Before building any custom widget, read its APG pattern, and prefer a well-tested headless library (React Aria, Radix, Headless UI, Angular CDK, Ark UI), which implements them (chapter 21).
Dialog (modal)
Use <dialog> with showModal(). It gives you, for free, the top layer, an inert background, Esc to close, focus moved inside, and the ::backdrop. Requirements:
- Name:
aria-labelledbypointing at the dialog's heading. - Initial focus: the first input, or the least destructive button. For long content, the heading (
tabindex="-1"). - Focus contained while open, and returned to the trigger on close.
- Esc closes it. Also provide a visible close button.
- Prevent background scrolling (
body:has(dialog[open]) { overflow: hidden }). - Use
role="alertdialog"for urgent confirmations that need a response.
Non-modal surfaces (side panels, chat widgets) use dialog.show() or the Popover API, without trapping focus.
Tabs
<div class="tabs">
<div role="tablist" aria-label="Account settings">
<button role="tab" id="t-profile" aria-controls="p-profile" aria-selected="true">Profile</button>
<button role="tab" id="t-security" aria-controls="p-security" aria-selected="false" tabindex="-1">Security</button>
</div>
<div role="tabpanel" id="p-profile" aria-labelledby="t-profile" tabindex="0">…</div>
<div role="tabpanel" id="p-security" aria-labelledby="t-security" hidden>…</div>
</div>
Keyboard: Tab moves into the tablist (to the selected tab), Left and Right arrows move between tabs with a roving tabindex, Home and End go to the first and last, and Tab moves on into the panel. Activation can be automatic (arrow keys select, best when panels are cheap) or manual (arrows move focus, Enter or Space selects, best when panels load data). If the "tabs" actually navigate to different URLs, they're links in a nav with aria-current="page", not ARIA tabs.
Menu and menu button
A menu button (aria-haspopup="menu", aria-expanded) opens a role="menu" containing menuitems. Expected keyboard behaviour: Enter, Space or Down opens it and focuses the first item; Up and Down move; Home and End jump; typing a character jumps to items starting with it; Esc closes it and returns focus to the button; Tab closes it and moves on. Use it for actions ("Duplicate", "Archive", "Delete"), as in an app's context menu. For a list of navigation links in a dropdown, use a disclosure (a button with aria-expanded that shows a list of links) instead of an ARIA menu.
Tree
role="tree" with treeitems (aria-expanded on parents, aria-level, aria-setsize, aria-posinset, and nested role="group") suits file explorers and nested navigation. Keyboard: Up and Down move through visible items; Right expands, or moves to the first child; Left collapses, or moves to the parent; Home and End; * expands all siblings; type-ahead. It's complex to build. For simple nested navigation, nested lists of links with disclosure buttons are often enough and easier to get right.
Grid
role="grid" is an interactive two-dimensional widget (spreadsheets, editable data tables, calendars) where arrow keys move between cells, and Enter or F2 edits. Don't use role="grid" for a read-only data table. Use a native <table>, which screen readers navigate with table commands. Grids need careful focus management (one tab stop, arrow-key movement between cells, managing focus inside cells), virtualisation support (aria-rowcount, aria-rowindex), and sorting (aria-sort). AG Grid, TanStack Table with React Aria, and similar libraries implement it.
Combobox
A combobox is an input with a popup of suggestions (autocomplete, searchable select). It's the hardest common pattern, and ARIA 1.2's pattern is the one to follow:
<label for="city">City</label>
<input id="city" role="combobox" aria-autocomplete="list" aria-expanded="true"
aria-controls="city-list" aria-activedescendant="city-opt-2">
<ul id="city-list" role="listbox" aria-label="Cities">
<li id="city-opt-1" role="option">Hyderabad</li>
<li id="city-opt-2" role="option" aria-selected="true">Hubli</li>
</ul>
Focus stays in the input while aria-activedescendant points at the highlighted option. Down and Up move through options, Enter selects, Esc closes (and clears on a second press), and typing filters. Announce the result count with a polite live region. Before building one, consider native <select>, <input list> + <datalist>, or customisable select (chapter 13), or use React Aria's or Downshift's combobox.
Tooltip
A tooltip is a small, non-interactive description that appears on hover and focus: role="tooltip", referenced by the trigger's aria-describedby. Requirements (WCAG 1.4.13): dismissible with Esc, hoverable without disappearing, and persistent while hovered or focused. Never put essential information or interactive content in a tooltip. Touch users can't hover, so use a toggletip (a button that reveals a popover) or visible text instead. The Popover API (popover="hint" for tooltips, plus anchor positioning, chapter 14) is becoming the native foundation.
Accordion
An accordion is a stack of headings, each with a button that expands a section:
<h3>
<button aria-expanded="false" aria-controls="sect-1" id="acc-1">Shipping policy</button>
</h3>
<div id="sect-1" role="region" aria-labelledby="acc-1" hidden>…</div>
The heading keeps the outline intact, and the button carries aria-expanded. Enter or Space toggles it, and arrow-key navigation between headers is optional. <details>/<summary> gives you a native single disclosure for free, and the name attribute groups several <details> into an exclusive accordion where only one is open at a time, without JavaScript. With hidden="until-found", collapsed content stays searchable with find-in-page.
Testing accessibility
A practical testing stack:
- Linting:
eslint-plugin-jsx-a11y(React) and Angular ESLint's template accessibility rules. - Automated checks in tests and CI: axe-core via
@axe-core/playwright,jest-axeorvitest-axe, and Storybook's accessibility addon. Lighthouse's accessibility audit. - Role-based testing: write tests that find elements the way users do, with
getByRole("button", { name: "Save" })in Testing Library and Playwright (chapter 26). If your test can't find an element by role and name, neither can a screen reader. - Manual keyboard pass: unplug the mouse and complete every critical flow. Is focus always visible? Is the order logical? Are there no traps? Do Esc, Enter and the arrow keys work?
- Screen-reader pass: NVDA + Chrome or Firefox, and VoiceOver + Safari (macOS and iOS), on the key flows.
- Zoom, reflow and contrast: zoom to 200% and 400%, check at 320 px width, test forced colours and dark mode.
- Real users: usability testing with disabled people finds what checklists miss.
Lab: accessibility, tested
These experiments use axe-core 4.14 (the engine behind Lighthouse's accessibility audit and many CI tools), Playwright's accessibility-tree snapshots and keyboard driving in Chromium 153, and a ten-line implementation of WCAG's contrast formula.
Experiment 1: what automated checking catches, and misses
The Start here section ran axe on the bad and fixed lunch-order pages: seven violated rules, then none. Compare that against the full list of real problems on the bad page:
| Problem on the bad page | Who it hurts | axe reported it? |
|---|---|---|
Images without alt |
screen-reader users | yes (image-alt) |
| Icon-only link with no name | screen-reader and voice-control users | yes (link-name) |
No lang on <html> |
screen readers pronounce in the wrong language | yes |
| Low-contrast hint text and button | low-vision users, everyone in sunlight | yes (color-contrast) |
No <h1>, no landmarks |
screen-reader navigation | yes (best-practice rules) |
Clickable <div> instead of a button |
keyboard, switch and screen-reader users: they can't press it | no |
:focus { outline: none } |
keyboard users can't see where they are | no |
| Placeholder used as the only label | users with memory or cognitive impairments; the name vanishes on typing | no (axe accepts a placeholder as a name) |
Generic <title>Order</title> |
screen-reader users switching tabs | no |
Five of nine found. The ones axe missed are about behaviour and quality, which a rule engine can't judge from markup: is this div meant to be a button? Is this alt text meaningful? Treat automated checks as a floor: run them in CI (with @axe-core/playwright or Lighthouse CI) so regressions can't merge, and add keyboard and screen-reader checks to your definition of done.
Experiment 2: the contrast formula
WCAG defines contrast from relative luminance, which converts sRGB to linear light and weights green most (our eyes are most sensitive to it):
function luminance(hex) {
const [r, g, b] = [1, 3, 5].map(i => parseInt(hex.slice(i, i + 2), 16) / 255)
.map(c => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4));
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}
const contrast = (fg, bg) => { const [a, b] = [luminance(fg), luminance(bg)].sort((x, y) => y - x); return (a + 0.05) / (b + 0.05); };
light grey hint on white #aaaaaa on #ffffff: 2.32:1 fails
darker grey hint on white #595959 on #ffffff: 7.00:1 AAA
white on orange button #ffffff on #f5a623: 2.03:1 fails
white on brown button #ffffff on #8a4b08: 6.79:1 AA
black on white #000000 on #ffffff: 21.00:1 AAA
#767676 on white #767676 on #ffffff: 4.54:1 AA
The ratio runs from 1:1 (identical) to 21:1 (black on white). Brand oranges and yellows almost always fail with white text: use dark text on them, or darken the brand colour for text use. #767676 is worth remembering as the lightest grey that passes AA on white. WCAG 3 is developing a perceptual model (APCA) that treats light-on-dark and font weight more accurately, but WCAG 2.2's ratio is what laws reference today.
Experiment 3: a native modal dialog versus a div
The same "Delete order 42?" confirmation, as <dialog> opened with showModal(), and as a positioned <div>. Tab was pressed four times from the initial focus:
<dialog>.showModal(): button#cancel "Cancel" → button#ok "Delete" → (body) → button#cancel "Cancel" → button#ok "Delete" → Escape → open: false
div "modal" : button#open "Delete order" → a "Help" → button#fcancel "Cancel" → button#fok "Delete" → (body)
clicks on the button behind the modal: 0 | matches :modal: true | after closing: 1
showModal() moved focus into the dialog, kept Tab cycling inside it (the stop at "(body)" is focus passing to the browser's own UI before returning), closed on Escape, and made the rest of the page inert: a real mouse click on the button behind it did nothing until the dialog closed. The div version left focus on the page behind, let Tab wander through hidden content, and needs about 60 lines of JavaScript (focus trap, Escape handler, inert on siblings, focus restoration, aria-modal) to match. The <dialog> element has been Baseline since 2022; there's no longer a reason to hand-build modals.
Experiment 4: reflow at 400% zoom, and reduced motion
WCAG's reflow criterion requires content to work at a width of 320 CSS pixels without two-dimensional scrolling, which is what a 1280 px-wide window shows at 400% zoom:
320px viewport, fixed-width layout: page width 968px → horizontal scrolling: true
320px viewport, fluid layout : page width 320px → horizontal scrolling: false
A fixed width: 960px forces a low-vision user to scroll sideways on every line; max-width with a wrapping flex layout reflows. And with the operating system's "reduce motion" setting emulated:
prefers-reduced-motion: no-preference → running animations: 1
prefers-reduced-motion: reduce → running animations: 0
The page honoured the user's request by turning its slide-in animation off. Large motion (parallax, zooming transitions, auto-playing carousels) can cause dizziness and nausea for people with vestibular disorders; keep a subtle fade if the animation carries meaning.
Try it yourself
- Run axe on a site you work on. Then do the five-minute manual check from Start here. How many issues did the manual check find that axe didn't?
- Build the div "modal" from experiment 3 properly (focus trap, Escape, inert background, focus return), then delete it all and use
<dialog>. - Pick your product's brand colours and compute their contrast against white and black text. Which text colour does each need?
- Turn on VoiceOver or NVDA and complete a purchase or form on a site you know, without looking at the screen. Note every place you got stuck.
Revision sheet: accessibility
Key ideas
- Accessibility serves permanent, temporary and situational disabilities; WCAG 2.2 AA is the usual legal and contractual target; POUR organises its criteria.
- Semantic HTML first: native elements bring roles, names, states, focusability and keyboard behaviour; ARIA only changes semantics, never behaviour.
- Accessible name computation:
aria-labelledby>aria-label> native label (<label>,alt,<caption>,<legend>) > content >title/placeholder; descriptions viaaria-describedby. - Keyboard: everything operable with Tab/Shift+Tab, Enter, Space, arrows and Escape; logical focus order; visible
:focus-visible; no keyboard traps; rovingtabindexinside composite widgets. - Focus management in SPAs: move focus to new content or the main heading after navigation; return focus when dialogs close;
inertfor background content. - Live regions (
aria-live="polite",role="status",role="alert") announce dynamic updates; the region must exist before its content changes. - Visual: contrast 4.5:1 text, 3:1 large text and UI components; reflow at 320 CSS px; text spacing; don't rely on colour alone;
prefers-reduced-motion; target size at least 24 × 24 CSS px (WCAG 2.2). - Widget patterns from the ARIA Authoring Practices Guide: dialog, tabs, menu button, combobox, tree, grid, accordion, tooltip.
- Testing: automated (axe, Lighthouse) in CI + keyboard + zoom + screen readers (NVDA, JAWS, VoiceOver, TalkBack) + users with disabilities.
Numbers to remember
- 1 in 6 people live with a significant disability (WHO).
- Contrast: 4.5:1 normal text, 3:1 large text (24 px, or 18.66 px bold) and UI components;
#767676on white = 4.54:1. - Reflow at 320 CSS px (400% zoom of 1280 px); text resizable to 200%.
- Target size minimum 24 × 24 CSS px (AA, WCAG 2.2); 44 × 44 recommended.
Pitfalls
- Clickable
divs,href="#"buttons, icon-only controls without names. - Removing outlines; focus hidden behind sticky headers (WCAG 2.2 "focus not obscured").
- Placeholder-only labels; error messages not tied to fields (
aria-describedby,aria-invalid). aria-labelthat contradicts visible text (breaks voice control); redundant or wrong roles.- Live regions inserted along with their content (not announced).
- SPA route changes that leave focus on a removed element.
- Believing a zero-violation automated report means accessible.
Glossary
- Accessible name: what assistive technology announces for an element.
- Accessibility tree: the browser's semantic tree exposed to platform accessibility APIs.
- Landmark: a page region role (banner, navigation, main, complementary, contentinfo, search, form, region).
- Inert: content that can't be focused, clicked or found by assistive tech.
- Roving tabindex: one tab stop per widget, with arrow keys moving within it.
- VPAT / ACR: a vendor's accessibility conformance report against WCAG.