Accessibility (a11y)
Implement web accessibility — WCAG guidelines, ARIA roles, keyboard navigation, color contrast, focus management, and AI-powered accessibility auditing.
Premium Course Content
This lesson is part of a premium course. Upgrade to Pro to unlock all premium courses and content.
- Access all premium courses
- 1000+ AI skill templates included
- New content added weekly
🔄 Recall Bridge: In the previous lesson, you mastered responsive design — fluid typography, responsive images, and mobile-first layouts. Now let’s ensure your pages are usable by everyone, including people who navigate with keyboards, screen readers, or other assistive technology.
Accessibility isn’t a feature — it’s a quality attribute of all good frontend code. An estimated 15-20% of the global population has some form of disability. Beyond ethics, accessibility is legally required in many jurisdictions and improves usability for everyone.
WCAG Quick Reference
WCAG (Web Content Accessibility Guidelines) has four principles:
| Principle | Meaning | Key Requirements |
|---|---|---|
| Perceivable | Users can perceive content | Alt text, contrast, captions |
| Operable | Users can interact | Keyboard nav, no seizure-inducing content |
| Understandable | Content is clear | Readable text, predictable navigation |
| Robust | Works with assistive tech | Valid HTML, ARIA when needed |
Conformance levels:
- A: Minimum (essential barriers removed)
- AA: Standard (most organizations target this)
- AAA: Enhanced (strictest, not always achievable)
Keyboard Navigation
Every interactive element must be keyboard-accessible:
| Action | Keyboard | Requirement |
|---|---|---|
| Navigate between elements | Tab / Shift+Tab | Logical tab order |
| Activate button/link | Enter (links), Enter/Space (buttons) | All clickable elements |
| Navigate within component | Arrow keys | Dropdowns, tabs, menus |
| Dismiss/close | Escape | Modals, dropdowns, tooltips |
| Submit form | Enter | From any form field |
Focus management rules:
| Rule | Implementation |
|---|---|
| Visible focus indicator | outline or box-shadow on :focus-visible |
| Never remove focus outline | Don’t use outline: none without replacement |
| Logical tab order | Match visual order, use tabindex="0" sparingly |
| Focus trapping in modals | Tab stays inside the dialog until closed |
| Focus restoration | After closing modal, return focus to trigger |
AI prompt for keyboard audit:
Audit this HTML for keyboard accessibility: [PASTE]. Check: (1) Can all interactive elements receive focus? (2) Is the tab order logical (matches visual order)? (3) Do custom components (dropdowns, modals) support expected keyboard patterns? (4) Are there visible focus indicators? (5) Is focus managed correctly for dynamic content (modals trap focus, closing restores focus)?
ARIA: When HTML Isn’t Enough
ARIA rule: Use semantic HTML first. ARIA is for when native HTML doesn’t express the interaction pattern.
| Pattern | Native HTML | ARIA (if needed) |
|---|---|---|
| Navigation | <nav> | role="navigation" |
| Button | <button> | role="button" + tabindex="0" |
| Modal | <dialog> | role="dialog" + aria-modal="true" |
| Tab interface | None native | role="tablist", role="tab", role="tabpanel" |
| Live updates | None native | aria-live="polite" or role="alert" |
Common ARIA attributes:
| Attribute | Purpose | Example |
|---|---|---|
aria-label | Accessible name | <nav aria-label="Main"> |
aria-labelledby | Name from another element | <dialog aria-labelledby="title"> |
aria-describedby | Additional description | <input aria-describedby="help-text"> |
aria-expanded | Open/closed state | <button aria-expanded="false"> |
aria-hidden | Hide from screen readers | <span aria-hidden="true">★</span> |
aria-live | Announce dynamic changes | <div aria-live="polite"> |
aria-current | Current item indicator | <a aria-current="page">Home</a> |
Color & Contrast
| Requirement | WCAG Level | Ratio |
|---|---|---|
| Normal text | AA | 4.5:1 |
| Large text (18px+ bold or 24px+) | AA | 3:1 |
| Non-text elements (icons, borders) | AA | 3:1 |
| Normal text | AAA | 7:1 |
AI prompt for contrast checking:
Check all color combinations on my page for WCAG AA compliance. My colors: text #1f2937 on background #ffffff, link #3b82f6 on background #ffffff, button text #ffffff on button background #3b82f6. For any failing combinations, suggest the closest compliant color.
Reduced Motion
Respect users who prefer less animation:
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
}
✅ Quick Check: Your page uses a decorative icon (a star rating display using star emoji). Should the stars have alt text? (Answer: Decorative content that conveys information needs alt text. If the stars represent a 4/5 rating, add
aria-label="Rating: 4 out of 5"to the container andaria-hidden="true"to each individual star character. Purely decorative images that convey no information should have empty alt:alt="". The distinction is whether the visual conveys meaningful information.)
Accessibility Testing Workflow
| Step | Tool | Catches |
|---|---|---|
| 1. Automated scan | axe DevTools, Lighthouse | Missing alt, contrast, labels (~30-40%) |
| 2. Keyboard test | Your keyboard (no mouse) | Tab order, focus traps, missing interactions |
| 3. Screen reader | VoiceOver (Mac), NVDA (Windows) | Announcement order, missing labels, live regions |
| 4. Zoom test | Browser zoom to 200% | Content overflow, truncation |
| 5. Color test | Disable CSS colors | Information not conveyed by color alone |
Key Takeaways
- Automated testing catches only 30-40% of accessibility issues: after running axe/Lighthouse, manually tab through the page (keyboard test), use a screen reader (announcement test), and zoom to 200% (visual test) to find the problems tools miss
- Dynamic content (notifications, form errors, loading states) is invisible to screen readers unless announced: use
aria-live="polite"for informational updates androle="alert"for urgent messages — this is the most commonly missed accessibility requirement in AI-generated code - Color contrast is measurable and non-negotiable: 4.5:1 for normal text, 3:1 for large text (WCAG AA) — when a design fails contrast, suggest the closest compliant color rather than a completely different color to maintain design intent while meeting the standard
Up Next
In the next lesson, you’ll optimize frontend performance for Core Web Vitals — LCP, CLS, and INP — making your pages fast on any connection and device.
Knowledge Check
Complete the quiz above first
Lesson completed!