Skip to the content

Lesson 13 of 296

Accessibility

What you will learn

  • What accessibility is and who it helps
  • What WCAG is
  • How people use the web without a mouse or without sight
  • Keyboard access and focus
  • Colour contrast
  • What ARIA is and its most important rule
  • How to test your own pages
On this page

What is accessibility?

Accessibility means building websites that everyone can use, including people with disabilities. It is often written as a11y (a, then 11 letters, then y).

It helps people who:

  • are blind or have low vision and use a screen reader (software that reads the page out loud) or zoom
  • are colour-blind
  • cannot use a mouse and use only a keyboard or a switch device
  • are deaf and need captions on videos
  • have conditions that affect reading, memory or attention

It also helps people with temporary problems (a broken arm) or difficult situations (bright sunlight on a phone screen, a noisy train).

In the UK, the Equality Act 2010 requires service providers to make reasonable adjustments for disabled people, and public sector websites have specific accessibility regulations. Accessibility is often a requirement in job adverts, especially for government, banking, legal and police work.

WCAG

WCAG (Web Content Accessibility Guidelines) is the international standard for web accessibility. It has three levels: A, AA and AAA. Most organisations aim for level AA.

WCAG is built on four principles. The short name is POUR:

PrincipleMeaningExample
PerceivableUsers can see or hear the contentAlt text for images, captions for videos
OperableUsers can use every controlEverything works with a keyboard
UnderstandableUsers can understand the content and controlsClear labels and error messages
RobustIt works with many devices and assistive toolsValid, semantic HTML

How screen readers work

A screen reader reads the page from top to bottom, but users rarely listen to everything. They jump using shortcuts:

  • jump from heading to heading
  • jump to landmarks: <nav>, <main>, <footer>
  • list all links on the page
  • jump between form fields

All of this only works if the HTML is semantic. This is why Lessons 8 to 12 kept talking about headings, labels and semantic elements. Good HTML is most of accessibility.

Common screen readers: VoiceOver (built into Mac and iPhone), NVDA (free, Windows), JAWS (Windows), TalkBack (Android).

Keyboard access

Many users never use a mouse. Try using your own site with only these keys:

KeyAction
TabMove to the next link, button or field
Shift + TabMove back
EnterFollow a link or press a button
SpacePress a button, tick a checkbox
Arrow keysMove between radio buttons, scroll, move in menus
EscClose a pop-up

Rules:

  • Every action must work with the keyboard.
  • The Tab order should follow the visual order on screen.
  • Never trap the user. For example, a pop-up that cannot be closed with the keyboard.

Focus

Focus is the element that will receive keyboard input. The browser shows it with an outline, often a blue or black ring.

Never do this:   *:focus { outline: none; }

Removing the outline makes the site impossible to use with a keyboard, because the user cannot see where they are. If you do not like the default look, replace it with your own clear style, do not remove it.

tabindex

ValueEffect
tabindex="0"Adds an element to the normal Tab order
tabindex="-1"Can be focused by JavaScript, but not with Tab
A positive number, like tabindex="5"Forces a custom order. Avoid it. It almost always makes the order confusing.

If you use semantic elements such as <button>, <a> and <input>, you rarely need tabindex at all.

A skip link is a link at the very top of the page that jumps straight to the main content. Without it, keyboard users must press Tab through the whole menu on every page.

<a href="#main" class="skip-link">Skip to main content</a>
...
<main id="main">

It is usually hidden until it receives focus.

Colour and contrast

Contrast is the difference in brightness between text and its background. Low contrast (light grey text on white) is hard to read for many people.

WCAG level AA requires a contrast ratio of at least:

  • 4.5 : 1 for normal text
  • 3 : 1 for large text (about 24px, or about 18.5px when bold)

You can check contrast with free tools, and with the colour picker in Chrome dev tools.

Never use colour as the only signal. "Fields in red are required" fails for colour-blind users. Add a word or a symbol, such as "(required)".

ARIA

ARIA (Accessible Rich Internet Applications) is a set of attributes that give extra information to screen readers when HTML alone is not enough.

AttributeExampleWhat it does
aria-label<button aria-label="Close">X</button>Gives a name to an element that has no visible text name
aria-describedbyaria-describedby="pw-hint"Links extra help text to a field
aria-expandedaria-expanded="false"Says if a menu or section is open
aria-hidden="true"On a decorative iconHides it from screen readers
aria-live="polite"On a message areaReads new messages out when they appear, for example "Saved"
rolerole="alert"Says what kind of thing an element is

The first rule of ARIA

If a native HTML element can do the job, use it instead of ARIA.

Bad:   <div role="button" tabindex="0" aria-label="Save">Save</div>
Good:  <button type="button">Save</button>

The bad version still needs JavaScript to work with Enter and Space. The <button> does everything already. A common saying is "No ARIA is better than bad ARIA", because wrong ARIA attributes can make a page harder to use.

Other important points

  • Set the page language: <html lang="en">, so screen readers use the right voice.
  • Give every page a clear, unique <title>.
  • Add captions to videos and transcripts to audio.
  • Let users zoom. Do not disable zoom in the viewport tag.
  • Avoid content that flashes more than three times per second. It can cause seizures.
  • Respect users who turned on "reduce motion" in their system settings. CSS can detect this with prefers-reduced-motion.

How to test

  1. Keyboard test: unplug the mouse and use the page with Tab, Enter, Space and Esc.
  2. Automatic test: run Lighthouse (in Chrome dev tools) or the axe browser extension. They find many problems, such as missing alt text and low contrast.
  3. Screen reader test: turn on VoiceOver or NVDA and listen to your page.
  4. Zoom test: zoom to 200% and check nothing breaks or overlaps.

Automatic tools find only part of the problems. Manual testing is still needed.

Common mistakes

  • Removing the focus outline.
  • Missing labels and missing alt text.
  • Low contrast text.
  • Clickable <div> elements.
  • Adding ARIA everywhere instead of using semantic HTML.
  • Pop-ups that cannot be closed with the keyboard.

How to say it in an interview

"Accessibility means everyone can use the site, including screen reader and keyboard users. I aim for WCAG AA. Most of it comes from semantic HTML: correct headings, labels, alt text, landmarks and real buttons. I keep visible focus styles, check contrast is at least 4.5 to 1, never use colour alone, and only add ARIA when no native element can do the job. I test with the keyboard, Lighthouse or axe, and a screen reader."

Key words

WordMeaning
Accessibility (a11y)Making sites usable by everyone, including disabled people
Screen readerSoftware that reads a page aloud
WCAGThe international accessibility guidelines
FocusThe element that receives keyboard input
Contrast ratioHow different text and background brightness are
ARIAAttributes that add accessibility information
Skip linkA link that jumps past the menu to the main content

Now prove it

This lesson is complete when you pass the quiz and all three practice levels.