Web Accessibility (a11y)
In the real world, we build ramps for wheelchairs and put braille on elevator buttons. On the web, we do the same thing!
Web Accessibility means making sure your website can be used by everyone, including people who:
- Are blind or have low vision.
- Cannot use a mouse (they use only a keyboard).
- Are colorblind.
- Have temporary injuries (like a broken arm).
1. The "Screen Reader" Perspectiveโ
A screen reader is software that reads the code of a website out loud. Imagine trying to use your favorite app with your eyes closedโthat is how many people experience your work.
How to help the Screen Reader:โ
- Use Semantic Tags: As we learned, using
<header>instead of a<div>tells the reader exactly where the top of the page is. - The "Alt" Rule: Always describe your images.
- โ
<img src="dog.jpg">โ The reader just says "Image." - โ
<img src="dog.jpg" alt="A golden retriever playing with a ball">โ The reader describes the scene.
- โ
2. The Keyboard Testโ
Some users cannot use a mouse due to motor disabilities. They navigate the web using the Tab key.
How to be Keyboard Friendly:โ
- Never remove the "Focus Outline": You know that blue box that appears around a button when you click it? That tells keyboard users where they are. Don't hide it!
- Use Buttons for Actions: If something is clickable, use a
<button>or<a>. If you use a<div>, a keyboard user cannot "tab" to it.
3. Color and Contrastโ
If the text color is too similar to the background color, many people won't be able to read it.
| Good Contrast | Bad Contrast |
|---|---|
| White on Black | Light Grey on Grey |
The Golden Rule: Don't use color only to show meaning.
- โ "Click the green button to save." (A colorblind user might see two grey buttons).
- โ "Click the green button labeled 'Save'."
4. Meaningful Link Textโ
Avoid using "Click Here" for your links. It gives no context to someone using a screen reader who is skipping from link to link.
- โ
To see our prices, <a href="/pricing">click here</a>. - โ
View our <a href="/pricing">full pricing plans</a>.
๐ฑ 5. The "a11y" Checklist for Beginnersโ
- โ Quick Checklist
- ๐ ๏ธ Helpful Tools
- Every image has an
altdescription. - The page has a clear
<h1>heading. - Form inputs have
<label>tags. - Text is large enough to read (at least 16px).
- The language is set:
<html lang="en">.
- Lighthouse: Built into Chrome DevTools. It gives you an accessibility score out of 100.
- WAVE: A browser extension that points out exactly what to fix on your page.
Big companies (like Google, Amazon, and Netflix) prioritize accessibility because itโs the law in many countries and it increases their total number of users. Learning this now makes you a much more valuable developer!
Accessibility isn't about following hard rules; it's about empathy. Build your sites so that everyone, regardless of their situation, can enjoy what you've created.