Accessibility & ARIA
8 min lesson
- Accessibility means building pages that everyone can use, including people who use screen readers, keyboards or zoom.
- Good HTML (headings, labels, alt text, semantic tags) is the first and biggest accessibility win.
- ARIA stands for Accessible Rich Internet Applications: extra attributes that describe roles and states to assistive tools.
- A role says what something is (role="button"); an aria-label gives it a spoken name; aria-expanded says whether it is open.
- Think of ARIA as sticky notes you attach to custom widgets so screen readers can announce them like native ones.
- Use ARIA only when no native element fits; a real <button> is always better than a div with role="button".
- This builds on Interactive elements and the earlier lessons: semantic HTML already gives most accessibility for free.
- The example shows a labeled search field, a skip link and an aria-live region; you will see a focusable skip link and text announced when it changes.
- Use semantic HTML first; ARIA is a patch, not a replacement.
- Every form field needs a label, and every image needs alt text.
- Test with a keyboard and a screen reader, not just by reading your code.
- Wrong ARIA is worse than no ARIA; if unsure, prefer native elements.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Accessibility</title>
</head>
<body>
<!-- A skip link lets keyboard users jump past the nav -->
<a href="#main" class="skip">Skip to main content</a>
<!-- Navigation with a spoken label -->
<nav aria-label="Main menu">
<a href="#">Home</a> | <a href="#">About</a>
</nav>
<!-- The main content target of the skip link -->
<main id="main">
<!-- A labeled search field -->
<label for="q">Search</label>
<input type="search" id="q" name="q" aria-describedby="hint">
<p id="hint">Type a word and press Enter.</p>
<!-- A live region announces text when it changes -->
<p aria-live="polite" id="msg">No results yet.</p>
</main>
<script>
// Simulate a result update; screen readers announce the new text
document.getElementById('msg').textContent = 'No results found.';
</script>
</body>
</html>What happens: A page with a "Skip to main content" link at the top, a navigation row (Home | About), and a main area with a "Search" field, a hint "Type a word and press Enter." and the text "No results found." announced by screen readers.
Breaking it down
skip link
<a href="#main">Skip to main content</a>The first focusable element. Keyboard users can skip repeated navigation and land on main.
aria-label
<nav aria-label="Main menu">Gives an element a spoken name. Useful when there are several navs on a page.
label and describedby
<input aria-describedby="hint">Links the field to extra help text. Screen readers read the hint after the label.
aria-live
<p aria-live="polite">Announces changes to this region. polite waits for a pause; assertive interrupts immediately.
Common ARIA attributes
| Attribute | Purpose |
|---|---|
| role | States what an element is |
| aria-label | A spoken name |
| aria-describedby | Links to helper text |
| aria-expanded | Open or closed state |
| aria-live | Announces content changes |
A helpful analogy
A page without accessibility is a building with stairs only. ARIA is the ramp added later; native HTML is a building designed with a ramp from the start. The designed ramp always works better.
Nesting rules
- 1.Only use ARIA when no native element does the job.
- 2.Every role must come with the keyboard behavior users expect, for example Enter on a button.
Common mistakes
Using a div as a button
Avoid
<div role="button" onclick="save()">Save</div>Use instead
<button type="button">Save</button>A real button works with the keyboard and screen readers by default. A div needs extra ARIA and script, and is easy to break.
Adding aria-label to an element that already has text
Avoid
<button aria-label="Save">Save</button>Use instead
<button>Save</button>A label overrides the visible text. If they differ, users see one thing and hear another.
Quick tips
- •Tab through your page; every action should be reachable without a mouse.
- •Try a free screen reader like NVDA or VoiceOver for five minutes; it teaches more than any checklist.