White text on a colored background feels like a safe default. It is not. On most of the bright, mid-tone colours that brands love, white text fails the contrast requirement in the Web Content Accessibility Guidelines, and the failure is invisible if you have good eyesight and a good screen.
Here are the measured numbers, a simple way to predict which colours pass, and what to change when one does not.
The threshold
WCAG 2.1 success criterion 1.4.3 asks for a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text (18 point or 14 point bold and up). The ratio is worked out from the relative luminance of the two colours, as the W3C explains.
Fifteen common colours, measured
Ratios for white text and for black text on each background. Pass means 4.5:1 or better.
| Background | White text | Black text |
|---|---|---|
#3b82f6 blue |
3.68:1 fail | 5.71:1 pass |
#2563eb darker blue |
5.17:1 pass | 4.06:1 fail |
#22c55e green |
2.28:1 fail | 9.22:1 pass |
#16a34a darker green |
3.30:1 fail | 6.37:1 pass |
#15803d dark green |
5.02:1 pass | 4.19:1 fail |
#ef4444 red |
3.76:1 fail | 5.58:1 pass |
#dc2626 darker red |
4.83:1 pass | 4.35:1 fail |
#f97316 orange |
2.80:1 fail | 7.49:1 pass |
#c2410c dark orange |
5.18:1 pass | 4.06:1 fail |
#facc15 yellow |
1.53:1 fail | 13.71:1 pass |
#a855f7 purple |
3.96:1 fail | 5.31:1 pass |
#9333ea darker purple |
5.38:1 pass | 3.90:1 fail |
#14b8a6 teal |
2.49:1 fail | 8.44:1 pass |
#0f766e dark teal |
5.47:1 pass | 3.84:1 fail |
#64748b slate |
4.76:1 pass | 4.41:1 fail |
The pattern is consistent. The saturated, lively mid-tone of almost every hue fails with white text. You usually have to go a full step darker before white passes.
Why black often wins on mid-tones
Contrast is a ratio of luminance, and the two ends are not symmetrical. Working it out:
- White text reaches 4.5:1 only when the background's relative luminance is 0.183 or lower.
- Black text reaches 4.5:1 when the background's luminance is 0.175 or higher.
Those ranges overlap in a sliver and otherwise cover everything, which has a useful consequence: for any background colour, either black or white text passes 4.5:1, and for most mid-tones it is black. A rare colour in the overlap, such as #db2777, passes with both (4.60:1 and 4.57:1).
So if a coloured background fails with white text, the first thing to try is not a new colour but dark text.
What to change
Work through these in order:
- Switch to dark text. Often the whole fix. A yellow button with white text is a failure at 1.53:1, but with near-black text it is one of the most readable combinations there is.
- Darken the background, keeping its hue. The change needed is smaller than people expect. White on
#3b82f6is 3.68:1. Moving the blue just slightly, to#2c72e5, reaches 4.52:1 and is still obviously the same blue. Going to#2563ebgives 5.17:1. - Make the text larger or bolder only if it is genuinely large text. At 3:1, white on
#3b82f6(3.68:1) passes for 18 point text, but not for a 14 pixel button label. Do not stretch the definition. - Put a scrim behind text on images. A photo has no single background colour, so the ratio changes from pixel to pixel. A semi-transparent dark layer between the photo and the text makes it predictable, and you then measure against the scrim's effective colour.
Things that are easy to miss
- Text over a gradient needs checking at its worst point, not its average. The same goes for the text in a CSS gradient you generate: measure against both ends.
- Hover and disabled states are separate pairs. A button that passes at rest can fail when its hover colour gets lighter.
- Placeholder text and grey captions are the usual casualties.
#999999on white is 2.85:1. - Colour alone must not carry meaning. Contrast is about legibility; red versus green status still needs an icon or label.
Borders and icons have a rule too
WCAG 2.1 success criterion 1.4.11, non-text contrast, asks for at least 3:1 for the parts of a control that identify it, and for graphics that carry meaning, such as icons. A pale input border is the classic failure. #d1d5db on white is 1.47:1 and #9ca3af is 2.54:1, so neither passes. #6b7280 reaches 4.83:1 and passes comfortably. In practice the rule bites when the border is the only thing telling people that a field exists. A button with a clearly different fill and a readable label is identified by those instead.
Disabled controls
WCAG exempts inactive components from its contrast requirements, which is sometimes read as permission to make disabled buttons nearly invisible. It is not a good idea. People still need to read the label to understand which option is unavailable and why, so keep the text legible even when it is deliberately muted.
Measure your own pairs
Do not rely on how it looks. Put your two colours into the colour contrast checker: it gives the ratio, shows a live preview, and when the pair fails it offers the nearest colours that pass, which is how the #2c72e5 figure above was found. If your colours are in another format, the colour converter translates between HEX, RGB, HSL and OKLCH first.