---
name: building-accessible-interfaces
description: Build and review web interfaces that meet WCAG 2.2 AA - native HTML elements, headings and landmarks, keyboard access and focus, labels and alt text, contrast, reduced motion, and target sizes - and check them with a scan, axe, and the keyboard. Use when writing or reviewing HTML, JSX, Vue, Svelte, Astro, or CSS.
license: MIT
compatibility: Optional - axe, for example through @axe-core/playwright.
metadata:
author: famiglio
category: frontend
---
<!-- cspell:ignore WCAG -->
# Building Accessible Interfaces
An accessible interface works with a keyboard, a screen reader, and high zoom. Aim for [WCAG 2.2](https://www.w3.org/TR/WCAG22/) level AA.
## Procedure
1. **Use native elements.** A `<button>` gets keyboard access, focus, and its role for free. A clickable `<div>` gets none of them. Add ARIA only when HTML cannot express what you need.
2. **Structure the page:** one `<h1>`, heading levels in order, `<main>`, `<nav>`, and a skip link to the main content.
3. **Support the keyboard.** Every control works with `Tab`, `Enter`, `Space`, and the arrow keys where expected. Never hide the focus outline without a visible replacement. In a dialog, trap the focus, close on `Escape`, and return the focus to the opener.
4. **Name everything:**
```html
<label for="email">Email</label>
<input id="email" type="email" aria-describedby="email-error" />
<p id="email-error">Enter an address such as ada@example.com.</p>
<button type="button" aria-label="Close">×</button>
```
Meaningful images get an `alt` text. Decorative images get `alt=""`.
5. **Check contrast and color.** Text 4.5:1, large text and controls 3:1. Show errors and statuses with text or an icon, not only color.
6. **Respect reduced motion:**
<!-- ‹guest · 2026-12-05› -->
```css
@media (prefers-reduced-motion: reduce) {
* {
animation: none;
transition: none;
}
}
```
7. **Make targets large enough:** at least 24 by 24 CSS pixels.
## Verification
```bash
git grep -nE '<(div|span)[^>]*(onClick|on:click|@click)' \
-- '*.tsx' '*.jsx' '*.html' '*.vue' '*.svelte' '*.astro' \
|| echo "No clickable div or span."
```
The scan finds only a few patterns. Also run axe and fix the critical and serious problems, complete the main tasks with the keyboard only, and zoom to 200%. Report what you did not check by hand.
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.