Text Over Images: Measure the Lightest Pixel, Not the Average
WCAG checks text on a photo against the pixel most like the text. A 54% black overlay keeps white text at 4.5:1 over any image; 40% drops to 2.84:1.
Put white text on a photo where 90% of the area behind the words is #333333 and 10% is a highlight at #F0F0F0. The average color of that area is #464646, and white on #464646 is 9.43:1, comfortably AAA. Over the highlight, the same white text is 1.13:1, and the letters that cross it disappear. WCAG judges this pair by the highlight, not the average.
What WCAG Measures Against an Image
Failure F83 covers text over background images under 1.4.3 and 1.4.6. Its test has two steps:
- Quick check: compare the text with the lightest area of the image behind it (for light text) or the darkest area (for dark text). If that pair meets the ratio, the text passes.
- If it does not, check the background behind each letter. Any letter without enough contrast fails the criterion.
The comparison is against the part of the image that looks most like the text, so the average of the area never enters into it. The thresholds are the usual ones: 4.5:1 for normal text and 3:1 for text at 24 px, or about 18.66 px bold (the full WCAG 2.2 table).
The incidental-text exemption does not help here. It covers text that is part of a picture with significant other visual content, such as a shop sign in a street photo. A headline set over a hero image is page content, and it has to pass.
Why the Average Lies
Most ways of picking a color from an image average something. A palette from k-means or median cut returns the mean of each cluster, so the lightest pixel in the photo is lighter than any swatch. A blurred thumbnail, a downscaled preview and "dominant color" helpers do the same. They answer "what color is this region overall", and F83 asks "what is the worst pixel under the letters".
For light text, find the brightest spot that sits behind a letter and measure that single pixel. For dark text, find the darkest one. Anti-aliased edges of the letters themselves don't count. You want the background color, not the blend at the edge of a glyph.
The Overlay Numbers
The reliable fix is a scrim, a semi-transparent layer between the image and the text. To guarantee a ratio over any photo, size the scrim for the worst possible pixel: pure white behind white text, pure black behind black text. Browsers blend overlays on the gamma-encoded sRGB values, so a black overlay at opacity a turns white into 255 × (1 − a):
| Target | Black overlay for white text | White overlay for black text |
|---|---|---|
| 3:1 (large text) | 42% | 35% |
| 4.5:1 (AA normal text) | 54% | 46% |
| 7:1 (AAA normal text) | 65% | 58% |
A 54% black overlay turns a white highlight into #757575, and white text on that is 4.60:1. A 46% white overlay turns black into #757575 too, and black text on it is 4.55:1. Both land on the same gray because #757575 is close to the point where a color's ratio against white equals its ratio against black, about 4.58:1.
A 40% black overlay is the setting to watch. Over a white highlight it produces #999999, and white text on that is 2.84:1, which fails even the 3:1 for large text.
.hero { position: relative; }
.hero::before {
content: "";
position: absolute;
inset: 0;
background: rgb(0 0 0 / 0.54);
}
A gradient scrim works if every letter sits where the gradient is at least 54% opaque. Check that at the narrowest breakpoint, where the text usually wraps lower into the gradient.
Halos and Shadows
A note on the contrast ratio definition in WCAG covers outlines around letters. A narrow outline counts as part of the letter. A wide outline that fills in the details of the letters acts as a halo and counts as the background. A solid dark halo around white text can therefore supply the contrast: you measure the text against the halo, not against the photo.
A soft text-shadow blur has no single color to measure, and its edge fades into the image. It helps readability, but it gives you nothing to put in a ratio. Use a scrim or a solid halo when you need a number.
Crops Change the Pixel
background-size: cover crops a photo differently on a phone and on a desktop, so the pixel behind the headline changes with the viewport. A pair checked at 1440 px wide can fail at 390 px. An overlay sized for the worst pixel avoids the problem, because it holds whatever part of the image ends up behind the text. Without one, check each breakpoint.
Try It
Take a screenshot of the design and load it into the Image Color Picker. In Eyedropper mode, hover over the brightest spot behind a letter (the 8× magnifier shows single pixels) and click to save it, then save the text color. Shift-click the two saved swatches to see their ratio. To confirm the overlay math, open the Contrast Checker with #FFFFFF on #757575: 4.60, AA pass. Change the background to #999999, the 40% overlay case: 2.84, every level fails.