Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Accessible design and contrast

After this lesson: I can check a page for contrast, text alternatives, labels and keyboard focus.

65 min lesson2 commandsUsability testing lab: audit a hard-to-use web shop and read a test in the browser

Accessible design lets more people use a page

Accessible design means building a page so that people with different needs can use it: poor sight, no mouse, a screen reader, a small phone. It matters because these are not rare cases, and the fixes are small and cheap when you make them early.

The lab's shop has grey text on white that some people cannot read. You will measure how bad it is with a number.

By the end of this lesson

Note

I can check a page for contrast, text alternatives, labels and keyboard focus.

Key words

WordWhat it means
Accessibilitywhether people with different needs can use the page
Contrast ratiohow different the text colour is from its background, from 1 to 21
Alt textwords that stand in for a picture that cannot be seen
Screen readersoftware that reads the page aloud
Labelwords tied to a form box that name it
Focusthe item the keyboard is on right now

The cells students fill in are left blank in this preview.

Contrast is the gap between text and background

The contrast ratio of two colours is a number from 1 to 21. Black on white is 21. Two equal colours give 1.

The usual contrast guideline asks for at least 4.5 for ordinary text, and at least 3 for large text. Below that, many people with poor sight, and anyone in bright sun, cannot read it.

Worked example: grey text on white by hand

StepGrey text #999999White background
Each colour channel as a share of 255153 / 255 = 0.6255 / 255 = 1.0
Made linear, so that mid greys count fairly0.31851.0
Lightness, the weighted sum of the three channels0.3185, because all three are equal1.0
Ratio: (lighter + 0.05) / (darker + 0.05)(1.0 + 0.05) / (0.3185 + 0.05) = 2.85

The cells students fill in are left blank in this preview.

Measure the shop's five colour pairs

Command
docker exec jupyter python3 steps/contrast.py

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

What the contrast script prints for the shop

WhereText on backgroundRatioVerdict
Body text#999999 on #ffffff2.85too low
Headline#222222 on #ffffff15.91enough
Links#9fbfe8 on #ffffff1.89too low
Error text#ff9999 on #ffffff2.05too low
Buy button#ffffff on #f2c94c1.59too low

The cells students fill in are left blank in this preview.

Pictures need alt text and boxes need labels

A person using a screen reader hears the page read aloud. It cannot describe a picture, so a picture needs alt text: a few words that say what it shows or does.

A form box needs a label tied to it. A placeholder is not enough, because it disappears when you type and a screen reader may not read it as the box's name.

Audit the shop's two pages

Command
docker exec jupyter python3 steps/audit.py

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

What the audit counts for the shop

PageProblemCount
Home pagePictures with no alt text3 of 4
Home pageLinks with vague text5 of 6
Checkout pageInputs without a label3 of 4
Checkout pageError messages that are only a code1
Style sheetRules that remove the focus outline1
Style sheetFont sizes under 14 pixels2 of 3

The cells students fill in are left blank in this preview.

A common mistake

Warning

Many people think accessibility is an extra for a small group. Everyone meets these limits at times: sun on a phone screen, a broken arm, a noisy train. A fix made for one need, such as a label or a clear contrast, helps almost everybody.

Keyboard users need to see where focus is

Some people cannot use a mouse. They press the Tab key to move from link to link and box to box. The focus outline shows where they are.

One rule in the shop's style sheet removes that outline. A keyboard user then has no idea where they are. The fix is to keep the outline or draw a clearer one.

Going further

Pick a page you use often. Write down its body text colour and its background, then work out the ratio with your function.

Try changing the grey to a darker one until the ratio reaches 4.5. How dark did you need to go?

About this lab and its source: Usability testing lab: audit a hard-to-use web shop and read a test in the browser

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.