Favorites

Accessibility Basics - HTML Tutorial

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

Web accessibility means making websites that everyone can use, including people with disabilities. That includes people who are blind and use a screen reader, people who can't use a mouse and rely on a keyboard, people with low vision who zoom in, people who are color blind and people with cognitive or learning disabilities.

Accessibility helps everyone else too. Clear headings, readable text and well-labeled forms make a site easier for every visitor, whether they're in a hurry, on a small phone screen or in bright sunlight.

The best news is that if you've followed this tutorial, you're already doing most of it. Accessibility starts with good, semantic HTML.

An Accessibility Checklist

Here are the key habits, gathered from the rest of the tutorial.

Structure

  • Set the page language with <html lang="en"> (see Structure).
  • Give every page a unique, descriptive title.
  • Use one h1, and don't skip heading levels (see Headings).
  • Use header, nav, main and footer to create landmarks (see Semantic Layout).
  • Use real lists for lists and real tables, with header cells and captions, for tabular data.

Text and Color

  • Make sure text has strong contrast with its background (see Colors).
  • Don't use color as the only way to convey information.
  • Use rem units for text, so it respects the visitor's text size settings (see Font Control).
  • Keep lines of text a comfortable length and give them enough line height.

Images and Media

  • Give every image an alt attribute, and use alt="" for purely decorative images (see Images).
  • Provide captions for videos and transcripts for audio.

Links and Buttons

  • Write link text that makes sense on its own, rather than "click here" (see Links).
  • Use a elements for things that go somewhere and button elements for things that do something. Don't make a div or span clickable instead.
  • Make links and buttons large enough to tap easily.

Forms

  • Give every field a connected label (see Form Basics).
  • Group radio buttons and related checkboxes in a fieldset with a legend.
  • Explain required fields and expected formats before visitors start typing (see Form Validation).

Keyboard Access and Focus

Many people navigate entirely with a keyboard. They press Tab to move from one link, button or form field to the next, Shift + Tab to move back, and Enter or Space to activate things.

Browsers show a focus indicator, usually an outline, around whichever element is currently selected. Never remove it without providing something just as clear in its place. The :focus-visible pseudo-class lets you style it, and it only shows the indicator when it's useful, such as when someone is using a keyboard:

Example: A Clear Focus Style
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #1e6bd6;
  outline-offset: 2px;
}

If you use real links, buttons and form fields, keyboard access works automatically. Problems usually appear when other elements are made to look and act like controls.

Respect Visitor Preferences

  • Zoom. Never stop people from zooming. Avoid viewport settings such as maximum-scale=1 or user-scalable=no. Make sure your page still works when zoomed to 200%.
  • Motion. Some people feel unwell when things on screen move a lot. The prefers-reduced-motion media query lets you tone down animations for anyone who has asked their device to reduce motion:
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

This is one of the rare cases where !important is the right tool, because it needs to override every other animation rule on the page.

Testing for Accessibility

You can catch most problems with a few quick checks:

  1. The keyboard test. Put your mouse aside and use Tab to go through the whole page. Can you reach and use everything? Can you always see where the focus is? Does the order make sense?
  2. The zoom test. Zoom in to 200% with Ctrl + + (Cmd + + on a Mac). Is everything still readable and usable, without text overlapping or getting cut off?
  3. An automated check. Chrome and Edge include Lighthouse in Developer Tools, which runs an accessibility audit and explains each problem it finds. Browser extensions such as axe DevTools or WAVE do the same.
  4. A screen reader. Try your page with the screen reader built into your computer: Narrator on Windows or VoiceOver on a Mac. Listen to how your headings, links and form fields are announced.

Automated tools are a great start, but they can only detect some kinds of problems, so the manual checks matter too.

Learn More

The internationally recognized standard for web accessibility is the Web Content Accessibility Guidelines (WCAG), published by the W3C. Many countries' accessibility laws refer to it. The W3C's Accessibility Fundamentals pages are a friendly place to start learning more.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee