Web Accessibility Essentials
Build pages that everyone can use: semantic HTML first, text alternatives, keyboard access and focus, colour contrast, ARIA only where needed, and how to test with a keyboard and a screen reader. Practise by fixing an inaccessible page.
1. Why accessibility is not optional
About one in six people lives with a disability: blind or low vision, deaf or hard of hearing, limited movement, or a cognitive difference. Many more are in temporary or situational conditions: a broken arm, bright sunlight on a screen, a noisy bus, a slow connection. Accessible sites are also easier for everyone, better for search engines and, in many countries, a legal requirement. The standard is WCAG (Web Content Accessibility Guidelines), organised around four principles, known as POUR: content must be Perceivable, Operable, Understandable and Robust.
The good news: most of accessibility is simply writing good HTML.
2. Start with semantic HTML
The right element gives you roles, keyboard behaviour and meaning for free:
| Instead of | Use |
|---|---|
<div onclick> or <span class="btn"> |
<button> |
A clickable <div> that goes somewhere |
<a href="..."> |
<div class="header"> |
<header>, <nav>, <main>, <aside>, <footer> |
| Bold text styled as a title | <h1> to <h6> in order |
Lines of <br> or <div> |
<ul>/<ol> for lists, <table> with <th> for data |
| Placeholder as a label | <label for> |
Rules of thumb:
- One
<h1>per page, and headings that nest in order (do not jump fromh2toh5). Screen-reader users navigate by headings. - Use landmarks (
<main>,<nav>, β¦) so users can jump to them. Label a<nav>if there is more than one (aria-label="Main"). - Set the page language:
<html lang="en">, so screen readers pronounce text correctly. - Give every page a unique, descriptive
<title>.
3. Text alternatives
- Informative images need
alttext that conveys the content or purpose:alt="Network diagram: two routers joined by a trunk". - Decorative images get
alt=""so assistive technology skips them (or use CSS backgrounds). - Images that are links describe the destination:
alt="Learn.GT home". - Icons in buttons need a name: a visually hidden text label or
aria-label="Close". - Video needs captions, and audio needs a transcript.
- Do not put text in images; it cannot be resized or read by screen readers.
4. Keyboard access and focus
Many people never use a mouse. Everything that works with a pointer must work with the keyboard:
- Tab moves forward, Shift+Tab back, Enter activates links and buttons, Space activates buttons, arrow keys move within widgets such as radio groups.
- Interactive elements must be focusable in a logical order (the order of the HTML). Avoid positive
tabindexvalues. Usetabindex="0"only to make a custom widget focusable, andtabindex="-1"for elements you focus with script. - Never remove the focus outline without replacing it with something equally visible:
:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }. - Provide a skip link as the first focusable element, so keyboard users can jump past a long menu:
<a class="skip" href="#main">Skip to content</a>
...
<main id="main">...</main>
.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; background: #fff; color: #000; padding: .5rem; z-index: 10; }
- Modals and menus must move focus into themselves when they open, keep it inside while open, close with Escape, and return focus to the trigger. The native
<dialog>element and theinertattribute make this much easier.
5. Colour and contrast
- Text must have enough contrast with its background: 4.5:1 for normal text, 3:1 for large text and for UI components such as input borders and icons (WCAG AA). Check with DevTools or a contrast checker.
- Never use colour alone to convey meaning. βRequired fields are redβ fails for colour-blind users; add text, an icon or a pattern.
- Support zoom and text resizing: use relative units (
rem), do not disable pinch-zoom, and make sure content reflows at 200% zoom without horizontal scrolling. - Respect user preferences:
prefers-reduced-motionfor animation,prefers-color-schemefor dark mode,prefers-contrastwhere you can.
6. ARIA: a small, careful tool
ARIA (Accessible Rich Internet Applications) attributes add information for assistive technology when HTML alone cannot express it.
- First rule: use a native element if one exists.
<button>beats<div role="button" tabindex="0">plus handlers for Enter and Space. - ARIA changes only what is announced, not what happens.
role="button"adds no keyboard behaviour. - All interactive ARIA controls must be keyboard-operable.
- Never hide focusable things with
aria-hidden="true". - Every control needs an accessible name.
Useful attributes: aria-label (a name when there is no visible text), aria-labelledby and aria-describedby (point to other elements), aria-expanded (is a disclosure open?), aria-current="page" (current page in a menu), aria-live="polite" or role="status" (announce updates, such as β3 results foundβ), and role="alert" (urgent messages).
7. Accessible forms and dynamic content
- Every field has a visible label connected with
for/id(see the forms lesson), and related fields are grouped with<fieldset>and<legend>. - Errors are text next to the field, linked with
aria-describedby, and announced withrole="alert"or by moving focus to them. - When script updates content (a cart count, a search result list), tell assistive technology with a live region; when you navigate in a single-page app, move focus to the new pageβs heading and update the title.
- Do not auto-play audio or trap people in timed interactions.
8. Testing accessibility
Automated tools catch only about a third of problems, so combine methods:
- Keyboard only: unplug the mouse. Can you reach and use everything? Is the focus always visible and in a sensible order?
- Automated checks: Lighthouse, axe DevTools, or
eslint-plugin-jsx-a11y. Fix what they find, then continue. - Zoom to 200% and resize the window to 320px.
- A screen reader: NVDA (free, Windows), VoiceOver (macOS, iOS), TalkBack (Android). Even ten minutes shows you what your page sounds like.
- Real users: people who use assistive technology every day find what you cannot.
9. Your turn: fix this page
The page below has accessibility problems. Fix it so that:
<html>has alangattribute.- Every
<img>has analtattribute (empty for the decorative one). - The βMenuβ control is a real
<button>with idmenu(not adivwithonclick). - There is exactly one
<h1>and the headings do not skip levels. - The search input has a label connected to it.
- The
<main>element hasid="main"and the first link on the page is a skip link to#main. - The
.notetext has a contrast ratio of at least 4.5:1 against the page background.
Your tasks
- β<html> has a lang attribute
- βEvery image has an alt attribute
- βThe menu is a real <button> with id=menu and no onclick attribute
- βThe menu button still works (clicking it toggles the menu-open class)
- βExactly one <h1>
- βHeadings do not skip levels
- βThe search input has a connected label
- βA skip link to #main comes first, and <main id="main"> exists
- β.note text has a contrast ratio of at least 4.5:1
10. What you learned
Accessibility is mostly good HTML: the right elements, text alternatives, keyboard support, enough contrast and a sparing use of ARIA. Build it in from the start, test with a keyboard, and your pages work for far more people. Next you add JavaScript to make pages respond.
π§ͺ Want to practise this on your own computer? See how to set up your lab →