--- name: accessibility-expert version: 1.0.0 description: >- Build interfaces usable by everyone: WCAG 2.2 conformance, semantic HTML, ARIA, keyboard navigation, screen readers and accessible forms. Use when the user mentions accessibility, a11y, WCAG, ARIA, screen readers, keyboard navigation, colour contrast, focus management, the European Accessibility Act or Section 508, or when the task involves making a component, form, modal or data table usable without a mouse or with assistive technology. category: design tags: [ accessibility, a11y, wcag, aria, screen-readers, keyboard-navigation, contrast, inclusive-design, forms, ] allowed-tools: - Read - Write - Edit - Bash(npm:*, npx:*, node:*) - Grep - Glob metadata: author: PCL Standard Library complexity: intermediate --- # Accessibility Expert Accessibility is a property of the markup and the interaction model, not a layer added afterwards. Most of it is achieved by using the right element; the rest is focus, contrast and honest testing. ## Core Concepts ### The Four Principles WCAG organises everything under POUR: - **Perceivable** — information must be available to at least one sense that works for the user: text alternatives, captions, sufficient contrast. - **Operable** — every function must be reachable and usable by keyboard, with enough time and no seizure triggers. - **Understandable** — predictable behaviour, readable text, errors that explain themselves. - **Robust** — valid markup and correct semantics, so assistive technology can interpret it. Conformance levels: A (minimum), **AA (the legal and practical target)**, AAA (specific contexts). Regulation generally requires AA — the European Accessibility Act applies from 28 June 2025 to consumer-facing digital products and services in the EU, and Section 508 applies to US federal procurement. ### The Right Element Is Most of the Work ```html
Submit
``` Native elements bring focus behaviour, keyboard handling, state announcement and platform conventions. Recreating them with `div` and ARIA means reimplementing all of it, and the reimplementation is where the defects live. ### ARIA's First Rule Is Not to Use It Use ARIA only when no native element expresses the semantics. Incorrect ARIA is worse than none: it overrides what the browser would have reported correctly. ## Keyboard Everything achievable with a mouse must be achievable with a keyboard, in a sensible order, with a visible focus indicator. ```css /* Never remove focus indication without replacing it */ :focus-visible { outline: 3px solid #0b5fff; outline-offset: 2px; } /* This is a defect, not a style choice */ *:focus { outline: none; } ``` WCAG 2.2 added **2.4.11 Focus Not Obscured**: the focused element must not be hidden behind a sticky header or cookie banner. Test by tabbing through the page with the header visible. ### Focus management Focus must go somewhere sensible after a view change, and must be trapped inside a modal while it is open. ```javascript function openDialog(dialog, invoker) { dialog.showModal(); // traps focus natively dialog.querySelector('[autofocus], button, [href], input')?.focus(); dialog.addEventListener('close', () => invoker.focus(), { once: true }); } ``` Returning focus to the element that opened the dialog is what keeps a keyboard user oriented. Losing focus to `` means starting the tab sequence again. For single-page navigation, move focus to the new page's heading and announce the change: ```javascript function onRouteChange(title) { document.title = title; const heading = document.querySelector('main h1'); heading.setAttribute('tabindex', '-1'); // focusable programmatically, not by tab heading.focus(); } ``` ### Skip links ```html …
…
``` ```css .skip-link { position: absolute; left: -9999px; } .skip-link:focus { left: 1rem; top: 1rem; position: fixed; z-index: 999; } ``` ## Semantics and Structure ```html

Invoices

Overdue

…
``` - **One `

` per page**, and headings that descend without skipping levels. Screen reader users navigate by heading; a broken outline is a broken map. - **Label repeated landmarks** — several `