--- name: building-accessible-interfaces description: Use when building or auditing any web UI for accessibility — keyboard navigation, screen readers, focus management, ARIA, color contrast, form labels and error announcements, reduced motion, or touch target size. Triggers include "is this accessible", "WCAG", "a11y", "screen reader", "keyboard navigation", "focus trap", "contrast ratio", "aria-label", or building modals, menus, tabs, comboboxes, toasts, and custom controls that must work without a mouse. --- # Building Accessible Interfaces ## Overview Accessibility is not a pass applied at the end. Almost every accessibility defect is a structural decision — a `div` that should have been a `button`, a state communicated only in color, a modal that never moved focus — and structural decisions are expensive to reverse. **Core principle:** Native semantic HTML is accessible by default. Every layer you add on top of it is a layer you now own the accessibility of. Target: **WCAG 2.2 Level AA**. ## The Iron Law ``` NO CUSTOM CONTROL WHERE A NATIVE ELEMENT EXISTS ``` A `
` needs a role, a tabindex, key handlers for Enter and Space, a focus style, and a disabled state. A `

Recent

…
``` **Rules:** - Decorative images: `alt=""`. Omitting `alt` entirely makes screen readers read the filename. - Informative images: `alt` describes the information, not the picture. A chart's alt is its finding. - Icons inside a labelled control: `aria-hidden="true"` so the name is not doubled. - Link text must make sense out of context. "Read more" ×8 on a page is useless; screen-reader users list links. - `aria-label` **overrides** visible text. If a button reads "Save" but has `aria-label="Submit"`, voice-control users saying "click Save" fail. Keep them matching. ## 4. Contrast | Content | Ratio | |---|---| | Body text | 4.5:1 | | Text ≥ 24px, or ≥ 18.66px bold | 3:1 | | Icons and UI boundaries that carry meaning | 3:1 | | Focus indicator vs. adjacent colors | 3:1 | Measure, do not estimate. See `designing-frontend-interfaces/references/color-and-theme.md` for the formula, and `applying-themes/scripts/check_contrast.py` for a runnable checker. **Color is never the only signal.** Add an icon, a label, a pattern, or a shape wherever color conveys state — see the table in that same reference. ## 5. Forms ```html

We'll only use this to send your receipt.

Enter an email address with an @.

``` | Rule | Why | |---|---| | Every input has a `