Web Accessibility (A11y)
Lesson 15 โข Expert Track
What You'll Learn
๐ก Think of It Like This
Accessibility is like a building with ramps, lifts, and braille signs. Just as physical spaces must be usable by everyone โ including wheelchair users and visually impaired people โ websites must work for people who use screen readers, keyboard-only navigation, or have colour vision deficiencies. Over 1 billion people worldwide have some form of disability.
1. Why Accessibility Matters
| Reason | Details |
|---|---|
| ๐งโ๐คโ๐ง Ethical | 15% of the world has a disability. The web should work for everyone. |
| โ๏ธ Legal | Many countries require WCAG compliance (ADA in US, EAA in EU). |
| ๐ SEO | Semantic HTML and alt text improve search engine ranking. |
| ๐ฅ UX | Accessible sites are better for everyone โ clearer, faster, more usable. |
2. Semantic HTML โ The Foundation
The single most important thing for accessibility: use the right HTML element for the job. Screen readers understand <button>, <nav>, and <main> โ but a <div> is meaningless.
| โ Don't | โ Do |
|---|---|
<div onclick="..."> | <button> |
<div class="nav"> | <nav> |
<div class="header"> | <header> |
<b>Title</b> | <h1>Title</h1> |
3. Keyboard Navigation & Focus
Many users navigate with keyboard only (Tab, Enter, Escape). All interactive elements must be focusable with a visible focus indicator.
/* โ
Always visible focus ring */
:focus-visible {
outline: 3px solid #3b82f6;
outline-offset: 2px;
}
/* โ NEVER do this without a replacement */
/* :focus { outline: none; } */Accessible Page Demo
A page with semantic HTML, focus indicators, skip links, and ARIA
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accessible Page</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: system-ui, sans-serif;
background: #0f172a;
color: #e5e7eb;
}
/* Skip link โ visible only on focus */
.skip-link {
position: absolute;
top: -60px;
left: 10px;
background: #3b82f6;
...4. Colour Contrast (WCAG Standards)
| Level | Normal Text | Large Text (18pt+) |
|---|---|---|
| AA (required) | 4.5:1 contrast ratio | 3:1 contrast ratio |
| AAA (recommended) | 7:1 contrast ratio | 4.5:1 contrast ratio |
๐ก Pro Tip: Use browser DevTools โ Accessibility panel to check contrast. Chrome shows contrast ratios when you inspect text elements.
5. Images & Alternative Text
| Image Type | Alt Text Rule | Example |
|---|---|---|
| Informative | Describe what it shows | alt="Golden retriever playing fetch" |
| Decorative | Empty alt (not missing!) | alt="" |
| Functional (logo/icon) | Describe the action/purpose | alt="Company homepage" |
โ ๏ธ Common Mistakes
- Using divs for buttons โ
<div onclick="...">lacks keyboard support, focus management, and screen reader semantics. Use<button>. - Removing focus outlines โ
outline: nonewithout a replacement makes keyboard navigation impossible. - Missing alt text โ Not the same as
alt=""(decorative). Missing alt entirely is an accessibility violation. - Low colour contrast โ Light gray text on white background fails WCAG. Test every text/background combination.
- Relying on colour alone โ Don't communicate status only with colour (red/green). Add icons, text, or patterns.
๐ Lesson Complete
You now understand the essentials of web accessibility:
- โ Use semantic HTML โ the #1 accessibility improvement
- โ All interactive elements must be keyboard accessible
- โ Always provide visible focus indicators
- โ Text must meet WCAG contrast ratios (4.5:1 for normal text)
- โ Images need descriptive alt text (or empty alt for decorative)
- โ
Label all form inputs with
<label>
Sign up for free to track which lessons you've completed and get learning reminders.