Color Contrast Explained
Contrast ratio quantifies how visible text is against its background. It's the single most important accessibility metric for color.
The formula
WCAG uses relative luminance. For each color:
L = 0.2126·R + 0.7152·G + 0.0722·B
Where R, G, B are linearized (0–1). Contrast ratio is:
ratio = (L_lighter + 0.05) / (L_darker + 0.05)
Range is 1:1 (identical) to 21:1 (black on white).
WCAG thresholds
| Type | Minimum |
|---|---|
| AA normal text | 4.5:1 |
| AA large text (18pt+ or 14pt bold) | 3:1 |
| AAA normal text | 7:1 |
| AAA large text | 4.5:1 |
| UI components | 3:1 |
How to fix low contrast
- Darken the text or lighten the background (or vice versa).
- Increase font weight — bold text needs less contrast.
- Add an outline or shadow (less ideal).
- Change the background from light color to white.
Common traps
- Gray text on white: #999999 fails AA — use #757575.
- Light-on-light gradients: always add an overlay.
- Opacity: a 50% opacity black text on white is not the same as #808080 gray — check the composite.