To make white text readable over a background image, put the whole caption on a dark layer and fade that layer into the photo above the words. To start, try a 56% black layer with pure white text. Keep the same opacity behind every line, including when the text wraps on a phone.
Compare three overlays on the same photo
The example uses the same lemon photo, crop, text position and white type. We measured the brightest point by relative luminance in each text area before adding the letters. That gives the lowest white-on-background contrast ratio anywhere in the measured rectangle.
- No overlay: 1.06:1. The lettering fades into the pale surface.
- 40% black: 3.02:1. The lettering is easier to see, but small text still falls below 4.5:1 in this area.
- 56% black: 5.18:1. Both the large line and a smaller caption can use the same background treatment in this example.
WCAG uses a minimum of 4.5:1 for typical text and 3:1 for qualifying large text, with defined exceptions. On a pure white pixel, ordinary sRGB compositing with 56% black gives roughly 4.95:1 against pure white text. These figures cover the colors in the measured setup. Check again if you change the text color, blend mode or background treatment. W3C’s contrast guidance
Add a fade above the caption in CSS
Put the caption at the bottom of the photo in normal grid layout. Its dark background grows with its contents. A pseudo-element fades upward for three rems, leaving all of the real text inside the darker band.
Live CSS example using an AI-generated Lemon and Rosemary Food Background from Stock Tour.
<div class="image-caption">
<div class="image-caption__copy">
<strong>Lemon & rosemary</strong>
<span>A bright finish for a spring menu</span>
</div>
</div>
.image-caption {
display: grid;
align-items: end;
min-height: 18rem;
background: #161b17 url("https://stock.kuronekoshop.jp/asset=351")
center / cover no-repeat;
}
.image-caption__copy {
position: relative;
padding: 1rem 1.25rem;
background: rgb(0 0 0 / 56%);
color: #fff;
overflow-wrap: anywhere;
}
.image-caption__copy::before {
content: "";
position: absolute;
inset: auto 0 100%;
height: 3rem;
background: linear-gradient(transparent, rgb(0 0 0 / 56%));
pointer-events: none;
}
.image-caption__copy strong,
.image-caption__copy span {
display: block;
}
Check the wrapped caption on a phone
Narrow the container until the second line wraps. Every letter should still sit on the dark band. Inspect the lightest spots immediately behind the text, including pale plates or reflections. If the band covers too much of the food, shorten the copy, use a taller crop, or place your headline in an area with more copy space.
Keep the wording in HTML so people can resize and select it. In this example the CSS background is decorative. If the photograph itself carries information, use a real image with meaningful alternative text alongside the caption. For the layer order and color stops, see MDN’s guide to overlaying CSS gradients.



