Sub topic 9
Leaving room for text overlays
This chapter assumes you know basic HTML and CSS, including img, width, height, and breakpoints. It also assumes you have read the chapters on aspect ratios and the focal point. A safe area is the part of a photo where text can sit without covering the subject or becoming hard to read.
Why safe areas matter
Hero banners often place a headline and a button on top of a photo. If the text lands on the subject's face or on a busy texture, readers lose either the photo or the words. You can avoid this by choosing a photo with calm space in it and then protecting that space when you crop.
Look for two kinds of space:
- Empty areas, such as sky, a wall, or out-of-focus background.
- Low-contrast areas, where the tones are even enough that text stays readable.
Plan the layout before you crop
Decide where the text goes first. Then pick the photo and the crop to match.
- Mark the focal point, such as a face or the main object.
- Mark the area for text on the opposite side.
- Check that the two areas do not overlap at your widest and narrowest crops.
A subject on the right third with open space on the left suits left-aligned text. A subject on the left suits the reverse.
Build it in CSS
Put the image and the text in one container. Position the text over the image and keep it on the side with open space.
<section class="hero">
<img src="hero-wide.jpg" width="1600" height="900" alt="A hiker resting on a ridge at sunrise">
<div class="hero-text">
<h1>Walk further this year</h1>
<a href="/trips">See trips</a>
</div>
</section>.hero {
position: relative;
}
.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: 45%;
padding: 2rem;
display: flex;
flex-direction: column;
justify-content: center;
color: #fff;
background: linear-gradient(to right, rgb(0 0 0 / 0.6), rgb(0 0 0 / 0));
}Here object-position pushes the subject toward the right, which leaves the left 45% open. The gradient darkens only the text side, so the photo stays bright elsewhere.
Keep text readable
Open space is not a guarantee of contrast. Check the text against the actual pixels behind it.
- Use a gradient or a semi-transparent panel behind the text.
- Aim for a contrast ratio of at least 4.5:1 for body-size text. Large headings need at least 3:1.
- Test with the lightest part of the photo under the text, since that is the worst case.
Common errors
- Checking only one screen size. A crop that leaves room at 1600px wide may push the subject under the text at 400px. Test each breakpoint, or use the
pictureelement to serve a crop made for narrow screens. - Putting text in the image file. Text baked into pixels cannot be selected, translated, or resized, and screen readers cannot read it. Keep text as HTML.
- Relying on a single color. White text on a bright sky fails. Add a gradient or choose dark text.
Exercise
A hero photo has the subject on the left. Which side should the headline go on, and which object-position x value would help keep the subject away from the text if the subject sits near the left edge of the image?
Show answer
Put the headline on the right, where the photo has open space. A low x value, such as 20%, keeps the left part of the image in view so the subject stays inside the frame while the right side remains free for text.