Guide

Colour contrast for the web: what the WCAG ratios mean and how to meet them

Published ยท 7 minute read

Low-contrast text is the most common accessibility failure on the web, and one of the easiest to fix. It is not only a matter for people with a diagnosed impairment: everyone reading a phone in sunlight, on a dim laptop or with tired eyes benefits from text that stands out from its background.

What a contrast ratio is

The Web Content Accessibility Guidelines (WCAG) define contrast as a ratio between the relative luminance of two colours, where luminance is a measure of how bright a colour appears to the eye:

ratio = (L_lighter + 0.05) / (L_darker + 0.05)

The scale runs from 1:1, two identical colours, to 21:1, black on white. Luminance is not the same as the lightness value in HSL. It weights the colour channels by how sensitive the eye is to each: green contributes about 72%, red about 21% and blue about 7%. That is why pure blue (#0000FF) is a dark colour for contrast purposes and pure yellow is a very light one, although both are "fully saturated".

The practical consequence is that you cannot judge contrast by eye or by the numbers in a colour picker. Measure it with a contrast checker.

The thresholds

ContentLevel AALevel AAA
Body text4.5:17:1
Large text (24px and up, or about 19px and up when bold)3:14.5:1
Interface components and meaningful graphics3:1โ€”

Level AA is the standard that most laws and procurement rules refer to, and the one to design for. AAA is a good target for long passages of reading text.

The third row is often forgotten. Since WCAG 2.1, the things a user needs to see in order to operate a page must also reach 3:1 against what is next to them: the border of a text field, the outline of a checkbox, the icon inside an icon-only button, the focus ring, the lines and slices in a chart.

What is exempt

Placeholder text is not exempt. Pale grey placeholders are among the most frequent failures, and a placeholder should not be doing the job of a label in any case.

Mistakes that recur

Grey text on white

Light grey looks refined in a design tool on a calibrated monitor. On white, the lightest grey that reaches 4.5:1 is about #767676. Popular "muted" greys such as #999999 (2.8:1) and #AAAAAA (2.3:1) fail clearly.

White text on a bright brand colour

White on a mid-tone orange, yellow, light green or sky blue almost always fails, because those hues are light in luminance terms. Either darken the colour for use behind text, or put dark text on it. Dark text on yellow is perfectly readable; white on yellow never is.

Text over images and gradients

The ratio must hold at the worst point, the place where the text crosses the part of the image closest to its own colour. Put a solid or semi-transparent layer behind the text, and check against the lightest and darkest regions it can cover.

Checking only the default state

Hover, focus, active, visited, selected and error states each have their own colour pairs. The focus indicator matters most: a keyboard user who cannot see where focus is cannot use the page at all.

Assuming dark mode passes because light mode did

The pairs are different and must be checked again. Dark themes also invite the opposite mistake. Pure white text on pure black is 21:1, which many people, particularly those with astigmatism, find harsh; an off-white on a very dark grey still passes easily and is more comfortable.

Colour must not be the only signal

Contrast is one requirement. A separate one says that colour alone must not carry meaning. Roughly one man in twelve and one woman in two hundred has some form of colour vision deficiency, most often difficulty telling red from green. So:

Building a palette that passes

Fixing colours one at a time after a design is finished is slow. It is easier to build the constraint into the palette:

  1. Create a numbered scale for each hue, for example 50 to 900, where each step is a consistent change in luminance. A palette generator gives you a starting point.
  2. Learn which steps pair safely. In a well-built scale, any two steps a fixed distance apart, typically five or more, reach 4.5:1. The rule then applies to every hue in the system.
  3. Define colours by role, not by value: text, muted text, border, surface, accent, danger. Check each role once against each surface it can sit on, in both themes.
  4. Reserve the lightest steps for backgrounds and the darkest for text. The middle of a scale is where pairs fail in both directions.
  5. Automate the check. Accessibility linters and browser developer tools flag failing pairs, and a test in continuous integration stops a regression from shipping.

The limits of the ratio

The formula is a simple model, and passing it does not guarantee that text is comfortable to read. It tends to overrate dark colour pairs and takes no account of font weight or size beyond the single "large text" cut-off. A hairline font at 4.5:1 is harder to read than a regular weight at the same ratio. Treat the thresholds as a floor that you must clear, then look at the result on a real phone, outdoors, at the size people will actually see it.

Tools used in this guide

More guides