Contrast is the difference in perceived lightness between text and its background. It is the most common accessibility failure on otherwise well-designed sites, and it is measurable. This guide explains the numbers and the practical fixes.
The ratio
WCAG defines contrast as:
(L1 + 0.05) / (L2 + 0.05)
where L1 is the relative luminance of the lighter color and L2 the darker. Relative luminance is not the same as HSL lightness; it weights the human eye’s sensitivity to red, green and blue differently. That is why two colors with similar HSL lightness can have very different contrast.
The result ranges from 1:1 (identical colors) to 21:1 (black on white).
Thresholds that matter
For WCAG 2.2 AA:
- Normal text: at least 4.5:1.
- Large text (roughly 18pt regular or 14pt bold and larger): at least 3:1.
- UI components and graphical objects needed to understand content: at least 3:1.
- Focus indicators: at least 3:1 against adjacent colors.
AAA raises normal text to 7:1, which is a useful target for long-form reading but not required by AA.
Common mistakes
Judging by eye on a bright screen
Perception changes with display brightness, ambient light and viewing angle. A ratio that feels fine on a calibrated monitor can fail on a phone outdoors. Calculate it.
Using brand color as text on white
Many brand colors are chosen for large surfaces, not small text. A vivid blue or orange may look strong in a logo and still fall below 4.5:1 as a 14px link. Darken it for text use, or place it on a surface that provides enough contrast.
Forgetting hover and disabled states
A link that passes in its default state can fail on hover if the color shifts toward the background. Disabled controls are exempt from some contrast requirements, but they should still be distinguishable.
Relying on color alone
Contrast is necessary, not sufficient. Error states, diff lines and chart series need text, icons or patterns in addition to color. Users with color vision deficiency may not distinguish red from green even at high contrast.
Fixing a failing palette
- Identify which pairs fail and by how much.
- Adjust lightness first; it moves the ratio most predictably.
- Keep hue and saturation close to the brand intent.
- Re-check the pair, then check the whole palette.
- Test the actual rendered text, not a swatch.
If a color is fixed by brand rules, change the background or the text size instead. Large display text has a lower threshold, but body copy should not be enlarged just to pass.
Transparency complicates everything
A color with alpha is composited with whatever is behind it. The effective contrast depends on the final rendered backdrop, which may be an image or a gradient. Measure the composited result, not the nominal color value.
A quick workflow
- Pick a text color and a surface.
- Compute the ratio with the color palette generator, which reports AA results for each swatch.
- Convert the approved values to the format your CSS uses with the color converter.
- Verify again in the browser with real content and states.
Contrast checks are cheap. Retrofitting a design system after launch is not.