Sub topic 9
Leaving room for text overlays
This chapter covers how to choose and crop a photo so text placed on top of it stays readable. It assumes you know basic HTML (the img element and its attributes), basic CSS (selectors, width and height), and responsive layouts with breakpoints. Earlier chapters covered focal points and CSS cropping. Here you will protect a second area of the image: the zone where text sits.
What a safe area is
A safe area is the part of an image where text can sit without covering the subject and without becoming hard to read. A photo used under a headline has two jobs. It must show its subject, and it must give the text a calm place to land.
These two jobs compete for space. The focal point wants to be prominent, and the text wants a quiet, even region. Good hero images resolve this in the photograph itself, by composing the subject toward one side and leaving the other side open. This open region is often called negative space.
A safe area has three properties:
- It does not overlap the focal point (a face, a product, the main action).
- It has fairly even tone and little detail, so letters do not compete with texture.
- It keeps enough contrast with the text color, either naturally or after an overlay.
Choose photos with room built in
The cheapest fix happens at selection time. When you browse for a hero image, look for these traits:
- The subject sits on a third line, not in the center. Chapter material on composition showed how this leaves one side open.
- The open side holds sky, a wall, a blurred background, a table, or water.
- The open area is large enough for your longest realistic headline, not only the placeholder.
- The image has spare canvas on every edge, so you can crop tighter later but could also crop looser.
A photo with a centered subject and a busy background has no safe area. You can still use it, but you will need a solid panel behind the text, not text directly on the photo.
Plan the text zone before you crop
Decide where the text will go first, then crop around both the subject and the text. A simple method is to draw two boxes on the original image: one around the focal point and one for the text. The crop must contain the first box fully and keep the second box clear of it.
Cropping changes the safe area
Each aspect ratio moves the safe area. A 16:9 crop of a landscape photo may leave a wide empty strip on the left. A 1:1 crop of the same photo may remove that strip entirely and push the subject close to where the text must go.
This is why a single object-position often fails on mobile. When the box becomes narrow and tall, the text stacks above or below the subject instead of beside it, so the safe area has to move too. Two common solutions are:
- Make a separate crop for narrow screens with the
pictureelement (covered in the art direction chapter), composed with the text at the top or bottom. - Move the text out of the image on small screens and place it below the photo, where it needs no safe area at all.
The second option is often the most reliable. Text over a photo on a 360px-wide phone leaves little room, and the text frequently grows larger than the open area.
Build a text overlay in CSS
Place the text over the image with a positioned container. The image stays in normal flow with its crop settings, and the caption layer sits on top.
<section class="hero">
<img
src="hero-1600.jpg"
srcset="hero-800.jpg 800w, hero-1600.jpg 1600w"
sizes="100vw"
width="1600" height="900"
alt="A hiker resting on a ridge at sunrise">
<div class="hero-text">
<h1>Walk the ridge before the crowds</h1>
<p>Guided sunrise hikes, every weekend.</p>
</div>
</section>.hero {
position: relative;
color: #fff;
}
.hero img {
display: block;
width: 100%;
aspect-ratio: 16 / 9;
object-fit: cover;
object-position: 75% 50%;
}
.hero-text {
position: absolute;
inset: 0 auto 0 0;
width: min(45%, 32rem);
padding: 2rem;
display: flex;
flex-direction: column;
justify-content: center;
background: linear-gradient(
to right,
rgb(0 0 0 / 0.6),
rgb(0 0 0 / 0)
);
}Here the hiker sits on the right side of the original photo. object-position: 75% 50% shifts the visible area toward the right, which keeps the hiker in frame and leaves the left side for the text. The container covers the left 45% of the hero and uses a gradient that fades to transparent, so the photo does not end in a hard edge.
Make the text readable
Even a good safe area can fail on contrast. Sky, snow, and sunlit walls all vary in brightness, and the actual pixels behind the text differ from one crop to the next. Use these techniques, starting with the lightest:
| Technique | How it works | Trade-off |
|---|---|---|
| Pick a calm region | Place text over even tone | Depends on the photo |
| Gradient overlay | Darkens only the text side | Can dim the subject if it spreads too far |
| Uniform scrim | Darkens the whole image evenly | Makes the photo look flat |
| Solid panel | Text sits on an opaque box | Hides part of the photo |
| Text shadow | Adds a soft halo behind letters | Helps small amounts of text only |
The Web Content Accessibility Guidelines (WCAG) set a minimum contrast ratio of 4.5:1 for normal text and 3:1 for large text. Check the contrast against the brightest part of the image behind your text, not the average. A headline that passes over a dark corner can fail where a cloud sits behind one word.
Edge cases to test
Text overlays break in predictable ways. Check each of these before you ship:
- Longer copy. A translated headline can be 30% longer. The text block may grow past the safe area and cover the subject.
- Larger user font sizes. People who raise their default font size get bigger text in the same space. Size the container with
remormin()and let it grow instead of fixing its height. - Different viewports. Check a narrow phone, a tablet, a laptop, and an ultrawide monitor. A 16:9 box can be very wide on a big screen, which moves the text far from the subject.
- Image fails to load. If the photo does not load, white text on a dark overlay may end up on a white page and disappear. Give
.heroabackground-colorthat matches the intended tone. - High contrast and forced colors modes. Backgrounds may be removed. Keep the text inside the container, so it can still be read on whatever background the user's system provides.
- Cropping moves the subject. After you change
object-positionfor a breakpoint, re-check that the focal point has not slid under the text.
A useful habit is to test with the longest headline you can imagine, then shorten it for production. The layout survives real content more often when it was built for a worst case.
Common mistakes
- Placing white text over a bright sky and trusting your eyes on one monitor.
- Fixing the text block's height in pixels, so it overflows at larger font sizes.
- Using one
object-positionfor every breakpoint when the layout changes from side-by-side to stacked. - Darkening the whole image so heavily that the photo loses its purpose.
- Adding the overlay in the image file instead of in CSS, which blocks translation and accessibility.
Exercise
A hero photo shows a cyclist on the right third of a 3:2 image with open sky on the left. You crop it to 16:9 with object-fit: cover and place the headline on the left. On phones, the layout becomes a tall 4:5 box and the headline now covers the cyclist. Name two ways to fix this without removing the photo.
Show answer
First, use a picture element with a separate narrow crop, composed so the cyclist sits in the lower part of the frame and sky fills the top for the headline, and serve it below your breakpoint. Second, on small screens move the headline out of the image and place it below the photo, so no safe area is needed. Adjusting object-position alone is a weaker option because a tall box crops away most of the side-to-side room that the wide layout relied on.
Exercise
Your headline is white and sits on a gradient overlay that is fully transparent at the right edge of the text block. A tester reports it is unreadable in one language. What is the most likely cause, and how would you check it?
Show answer
The translated headline is longer and extends into the transparent end of the gradient, where it sits on bright photo pixels. Check by testing with the longest translation, measure the contrast ratio against the brightest pixels behind the text (target 4.5:1 for normal text), and widen the text container or extend the dark part of the gradient so it covers the full text width.