Sub topic 11
Scrims, gradients and overlays for readable text
This chapter assumes you can already place text on an image and judge contrast by eye. It also assumes you know the basics of opacity and blend modes in a design tool, and that you can read short CSS snippets. Here you will learn how to add a layer between the photo and the type so the text stays readable, and how to do it without flattening the picture.
Why a layer is sometimes needed
Negative space is the first choice for text, because it needs no help. Often the photo has no calm area where the headline has to go. Busy texture, bright highlights and dark shadows can sit under the same line of type, so some letters pass the contrast check and others fail.
A scrim is a semi-transparent layer placed between the image and the text. It lowers the contrast range of the pixels behind the type. Three families of treatment cover most cases:
- Flat overlay: one color at one opacity across the whole image.
- Gradient scrim: a color that fades from opaque to transparent, usually from the edge where the text sits.
- Local panel: a bounded shape behind the text, such as a solid box, a tinted card or a blurred pane.
Choosing a treatment
The right treatment depends on how much of the image you are willing to give up.
| Treatment | What it does to the photo | Best for | Main risk |
|---|---|---|---|
| Flat overlay | Dims or tints everything evenly | Background-role images, full-bleed heroes with centered text | Muddy, flat image |
| Gradient scrim | Darkens one edge, leaves the rest intact | Content-role photos with text anchored to an edge | Visible band if the gradient is too short |
| Local panel | Leaves the photo untouched outside the box | Unpredictable images, user-uploaded photos | Looks pasted on if not aligned to the grid |
| Blur plus tint | Softens detail behind the text | Layouts where detail would compete with type | Costly to render, weak fallback |
The decision usually follows the image's role. A mood image can take a heavy flat overlay. A content image, where the viewer must read the picture itself, should lose as little as possible, so prefer a gradient or a panel.
The gradient scrim in practice
A gradient scrim darkens only the region that holds the text. The following CSS puts a dark gradient over a photo and anchors white text to the bottom edge.
.hero {
position: relative;
min-height: 24rem;
display: flex;
flex-direction: column;
justify-content: flex-end;
padding: 2rem;
color: #fff;
background:
linear-gradient(to top, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0) 60%),
url("coast.jpg") center / cover no-repeat;
}The gradient is listed first in the background property, so it is drawn on top of the image. The to top direction starts at the bottom edge with 70% black and fades to fully transparent at 60% of the box height. The text sits in the dark zone, and the upper 40% of the photo stays untouched.
In Figma, Photoshop or InDesign the same result comes from a rectangle filled with a linear gradient, from black at 70% opacity to black at 0%. Put it between the image and the text layer, and group it with the image so that moving one moves both.
Gradient settings that matter
- Start where the text starts. The darkest stop should sit behind the text block, not at the very edge of the frame.
- End before the focal point. If the gradient reaches the subject's face, it dims the part of the image the viewer should see first.
- Make the fade long enough. A short fade creates a hard edge that reads as a dark bar. A fade covering about half the frame looks natural.
- Fade from the same color to transparent. In some tools, fading to
transparentfades through gray. Usergba(0, 0, 0, 0)rather than the keywordtransparentto avoid a milky midpoint.
Calculating how dark the scrim needs to be
Do not guess an opacity. Take the brightest area behind the text, since that is the worst case, and compute the contrast after the scrim is applied. White text needs at least 4.5:1 for body-size text and 3:1 for large text under WCAG 2.x.
Take a pure white pixel under a black scrim. These are the results for white text:
| Scrim opacity | Resulting pixel | Contrast with white text | Passes 4.5:1? |
|---|---|---|---|
| 0.4 | about #999999 | about 2.9:1 | No |
| 0.5 | about #808080 | about 4.0:1 | No, passes 3:1 only |
| 0.6 | about #666666 | about 5.7:1 | Yes |
| 0.7 | about #4D4D4D | about 8.4:1 | Yes |
A scrim of 55% or more therefore guarantees body text even over pure white. Most photos are darker than pure white, so you can often go lower. Sample the lightest pixel behind the text with an eyedropper, apply the scrim, then measure the result.
Flat overlays and blend modes
A flat overlay is the simplest option. In CSS you can add a pseudo-element, so the markup stays clean:
.banner {
position: relative;
color: #fff;
background: url("market.jpg") center / cover no-repeat;
}
.banner::before {
content: "";
position: absolute;
inset: 0;
background: rgba(10, 20, 40, 0.55);
}
.banner > * {
position: relative;
}The ::before layer fills the box, and .banner > * lifts the content above it. Without that last rule, the overlay would paint over the text, because positioned elements stack in source order.
Tinted overlays use a dark version of a color from the image rather than pure black. This ties the type to the photo, as described in the chapter on color relationships. Blend modes such as Multiply can also darken evenly, but the result depends on the pixels beneath it, so the contrast you measure may not be what a different image would give.
Local panels and blur
When you do not control the image, a local panel gives the most predictable contrast. A solid or 85–90% opaque panel behind the text makes the result nearly independent of the photo. Align the panel's edges to the grid, and give the text the same internal padding on all sides.
A blurred panel keeps the feeling of the image but removes the fine detail that causes trouble. In CSS it uses backdrop-filter: blur(12px) with a semi-transparent background. Always set a background color that passes contrast on its own, because browsers or devices that do not support backdrop-filter will show only that color.
Common failures
- Overlay on everything. A heavy flat overlay on a content photo makes the whole page look dull. Use a gradient instead.
- Banding. Long gradients with small color changes can show visible steps on some screens. A slight noise texture or a longer fade hides them.
- Text shadows as the only fix. A soft shadow helps edges but does not fix the contrast of the glyph body. Use it as a supplement, not as a substitute.
- Checking one crop only. Cropping changes which pixels sit behind the text. Re-check after each crop, particularly on narrow screens.
- Scrim covering the focal point. If the subject becomes dim, move the text, change the crop or switch to a panel.
Exercise
White 18 px body text sits over a photo whose brightest area behind the text is pure white. You add a black gradient scrim that is 45% opaque at its darkest point behind the text. Does the text meet WCAG AA, and what would you change?
Show answer
No. At 45% black over white, the pixel is about #8C8C8C, which gives roughly 3.4:1 contrast with white text. Body text at 18 px needs 4.5:1. Raise the darkest stop to at least 55–60% opacity (about 4.7:1 at 55%), or move the text to a darker part of the photo, or place it on a local panel. Then re-measure the final composite.
Exercise
In the .banner example, what happens if you remove the rule .banner > * { position: relative; }, and why?
Show answer
The overlay can paint above the text. The ::before element is absolutely positioned, and positioned elements are painted after non-positioned content, so the dark layer covers the text and lowers its contrast. Making the children position: relative puts them in the same stacking layer, and later source order places them above the overlay.