Sub topic 8
Protecting the focal point
This chapter assumes you know the img element, basic CSS sizing, and how breakpoints work. It also assumes you have read the earlier chapters on aspect ratios and the principles of cropping. Here you will learn how to find the focal point of a photo, record it, and make sure every crop keeps it in view.
What a focal point is
The focal point is the part of a photo that carries its meaning. In a portrait it is the face, and in a product shot it is the product. In a photo of a baker at an oven, it is the baker's hands and the loaf.
A focal point is not always a single spot. A group photo may have a focal region, such as three faces side by side. Treat it as the smallest area you cannot lose without losing the message.
The focal point matters because the browser does not know about it. When CSS crops an image to fit a box, it keeps the center by default. If the subject sits off-center, the crop can cut off a head, a hand, or a product label.
Finding the focal point
Ask one question: if I could keep only a small rectangle of this photo, which rectangle would I keep? Then check it with two tests.
- The squint test. Squint at the photo or shrink it to a thumbnail. The area that still reads as the subject is your focal point.
- The extreme-crop test. Mentally crop the photo to a tall narrow strip, then a wide thin strip. Check that the focal point survives both.
Also check what must stay near the focal point. A person's eyes need some space in the direction they are looking. A product needs its logo or label. Cutting these off changes how the photo reads, even if the subject is technically still there.
Expressing the focal point as numbers
CSS needs numbers, so convert your focal point into percentages of the image's width and height. Measure from the top-left corner.
For example, take a photo where the baker's hands are about 30% of the way across and 40% of the way down. The focal point is 30% 40%.
You can estimate this in any image editor. Read the pixel position of the focal point, then divide by the image width and height.
def focal_point_percent(x_px, y_px, width_px, height_px):
"""Convert a focal point in pixels to CSS object-position percentages."""
x = round(x_px / width_px * 100)
y = round(y_px / height_px * 100)
return f"{x}% {y}%"
# A 2400 x 1600 photo with the subject at pixel (720, 640)
print(focal_point_percent(720, 640, 2400, 1600))This prints 30% 40%.
How object-position uses the focal point
When you set object-fit: cover, the image is scaled until it fills the box, and the overflow is cropped. The object-position property decides which part of the image stays visible.
.hero img {
width: 100%;
aspect-ratio: 16 / 9;
object-fit: cover;
object-position: 30% 40%;
}The image fills a 16:9 box, the browser crops the overflow, and object-position moves the visible area toward the subject instead of the center.
The percentage values work in a way that surprises many people. A value of 30% 40% does not mean "put the point 30% across the box at the center." It means the point that is 30% across the image lines up with the point that is 30% across the box. At 0% the image's left edge meets the box's left edge. At 100% the right edges meet. At 50% the image is centered.
This has a useful effect. The browser can only move the image by the amount it overflows. The focal point moves toward your chosen position but it is not guaranteed to land exactly there.
What the crop can and cannot do
The overflow depends on the difference between the image's ratio and the box's ratio. Consider these cases for a 3:2 photo.
| Box ratio | Overflow direction | What `object-position` controls |
|---|---|---|
| 3:2 | None | Nothing, the whole image shows |
| 16:9 | Top and bottom | The vertical value (the second one) |
| 1:1 | Left and right | The horizontal value (the first one) |
| 9:16 | Left and right, a lot | The horizontal value, with heavy cropping |
If the box has the same ratio as the photo, object-position does nothing. If the crop cuts only the top and bottom, the horizontal value has no effect. Knowing which axis is cropped tells you which number to adjust.
Edge cases
The focal point is near an edge
If the subject sits very close to a corner, a heavy crop may cut it off even at 0% or 100%. The image can move only until its edge meets the box edge. If the subject is still cut off, object-position cannot fix it. You need a different crop of the photo, which is the subject of the art direction chapter.
Several subjects
A photo with two important subjects far apart has no single focal point. Choose a position that keeps the more important one. If both must stay visible, avoid tall or narrow boxes for that photo, or use a separate crop.
Faces and eyes
Faces are the most common failure. A crop that removes the top of a head looks like a mistake, but one that cuts the head neatly at the forehead can look intentional. A crop at the chin or the joints, such as the neck, elbows, or knees, feels awkward. Keep eyes roughly in the upper third of the box when you can, and keep the whole head unless you are cropping tightly on purpose.
Content that changes
If editors upload photos to a content management system, you cannot hand-tune each one in CSS. Many systems let editors set a focal point when they upload. The system then writes the matching object-position value, usually as an inline style, or generates crops.
<div class="card">
<img
src="team-800.jpg"
width="800" height="600"
alt="Four colleagues around a whiteboard"
style="object-position: 62% 35%;">
</div>.card img {
width: 100%;
aspect-ratio: 1 / 1;
object-fit: cover;
}Here the CSS sets the shared crop rules, and the inline style carries the per-image focal point. This keeps the editor's choice with the image instead of in the stylesheet.
Zoomed-in crops
When a box is much narrower than the photo, the crop is severe, and the visible area may be only a third of the photo. A correct focal point still helps, but the result may be too tight to read. Check the smallest and the most extreme layouts, not only the common ones.
Common mistakes
- Relying on the center. Subjects are often placed on thirds lines, so the center crop is often wrong.
- Setting one focal point for every layout. A point that works in a wide banner may fail in a square card.
- Adjusting the wrong axis. Changing the horizontal value does nothing when only the top and bottom are cropped.
- Testing only on your own screen. Resize the window and check phones and wide monitors.
- Forgetting overlaid text. Text placed over the subject hides the focal point. Plan for it, as the next chapter explains.
Putting it together
A reliable routine for each important photo:
- Find the focal region with the squint test.
- Convert it to percentages.
- Set
object-positionon the cropped element. - Check the narrowest, widest, and in-between layouts.
- If the subject is lost at any size, make a separate crop.
Exercise
A 3:2 photo has its subject at about 80% across and 50% down. You display it in a square box with object-fit: cover. Which object-position value should you set, and why does the second number matter little here?
Show answer
Set object-position: 80% 50%. A square box is narrower than a 3:2 photo, so the browser crops the left and right sides, and the horizontal value (80%) decides which part stays visible. Because the box is cropped only horizontally, the image has no vertical overflow, so the vertical value has no visible effect.
Exercise
A 1600 x 1000 pixel photo has its focal point at pixel (400, 250). What object-position percentages describe it?
Show answer
400 / 1600 = 25% across and 250 / 1000 = 25% down, so the value is 25% 25%.