| name | accessibility |
| description | Accessibility (a11y) patterns and best practices for web apps. Use when building UI components, forms, modals, dropdowns, tabs, toggles, or any interactive elements. Also use when the user mentions ARIA, screen readers, keyboard navigation, focus management, color contrast, or accessible HTML. |
Accessibility (A11y) Quick Reference
Essential Rules
1. Semantic HTML
<div onclick="handleClick()">Click me</div>
<div class="header">Title</div>
<button onclick="handleClick()">Click me</button>
<h1>Title</h1>
<header>
<nav>...</nav>
</header>
<main>
<article>
<h1>Title</h1>
<section>...</section>
</article>
<aside>...</aside>
</main>
<footer>...</footer>
2. Images - Alt Text
<img src="chart.png" alt="Sales increased 40% in Q3" />
<img src="decoration.png" alt="" role="presentation" />
<figure>
<img src="complex-diagram.png" alt="Network architecture diagram" />
<figcaption>
Detailed description of the network architecture...
</figcaption>
</figure>
<button aria-label="Close modal">
<XIcon />
</button>
3. Form Labels
<label htmlFor="email">Email</label>
<input id="email" type="email" />
<label>
Email
<input type="email" />
</label>
<label htmlFor="email">Email</label>
<input
id="email"
type="email"
aria-invalid={!!error}
aria-describedby={error ? "email-error" : undefined}
/>
{error && <span id="email-error" role="alert">{error}</span>}
4. Focus Management
*:focus { outline: none; }
*:focus-visible {
outline: 2px solid #3b82f6;
outline-offset: 2px;
}
.skip-link {
position: absolute;
top: -40px;
left: 0;
padding: 8px 16px;
background: #000;
color: #fff;
z-index: 100;
}
.skip-link:focus {
top: 0;
}
<a href="#main-content" class="skip-link">Skip to main content</a>
<main id="main-content" tabindex="-1">...</main>
ARIA Attributes
Roles
<div role="banner">Header content</div>
<div role="navigation">Nav content</div>
<div role="main">Main content</div>
<div role="complementary">Sidebar</div>
<div role="contentinfo">Footer</div>
<div role="button" tabindex="0">Custom button</div>
<div role="dialog" aria-modal="true">Modal</div>
<ul role="listbox">
<li role="option">Option 1</li>
</ul>
<div role="alert">Error message</div>
<div role="status">Status update</div>
Common ARIA Attributes
aria-label="Close"
aria-labelledby="heading-id"
aria-describedby="description"
aria-expanded="false"
aria-selected="true"
aria-checked="true"
aria-pressed="false"
aria-disabled="true"
aria-hidden="true"
aria-invalid="true"
aria-live="polite"
aria-live="assertive"
aria-atomic="true"
aria-controls="panel-id"
aria-owns="child-id"
aria-haspopup="menu"
For accessible component patterns (modals, dropdowns, tabs, toggles), keyboard navigation, color contrast, live regions, and reduced motion support, see reference.md.
Quick Checklist
- All images have alt text (or alt="" for decorative)
- All form inputs have associated labels
- Focus is visible on all interactive elements
- Color is not the only means of conveying information
- Text has sufficient contrast (4.5:1 minimum)
- Page has logical heading structure (h1 > h2 > h3)
- Interactive elements are keyboard accessible
- Modals trap focus and return focus when closed
- Error messages are associated with inputs
- Page content is in a landmark region
- Skip link available for keyboard users
- No keyboard traps
- Motion can be paused/reduced (prefers-reduced-motion)