Sub topic 3
Different Crops for Different Screens
Assume you know basic HTML and CSS, including responsive breakpoints. You should also understand that a crop removes part of an image without changing the original file.
Different crops for different screens
A wide desktop hero may show a person from the waist up. On a narrow phone, the same crop can make the person too small. Use art direction, which means choosing a different crop for a different layout.
<picture>
<source media="(min-width: 800px)" srcset="baker-wide.jpg">
<img
src="baker-square.jpg"
width="800"
height="800"
alt="A baker lifting a loaf from a stone oven">
</picture>The source selects the wide crop on larger screens. The img remains the fallback and supplies the square crop on smaller screens. Keep the important subject inside the crop, especially when text or controls appear over the image.
Serving the right size with `srcset` and `sizes`
Art direction chooses the composition. Responsive image sizing chooses the file resolution. The srcset attribute lists available widths. The sizes attribute tells the browser how much layout space the image will occupy.
<img
src="team-800.jpg"
srcset="team-400.jpg 400w, team-800.jpg 800w, team-1600.jpg 1600w"
sizes="(min-width: 960px) 50vw, 100vw"
width="800"
height="600"
alt="Four colleagues around a whiteboard">Without accurate sizes, the browser may download an unnecessarily large file.
Choosing formats and compression
Use modern formats such as WebP or AVIF when your delivery system supports them. Compress photographs until visible detail begins to suffer. Compare the image at its displayed size, not only at 100% zoom. Avoid sending a 2400-pixel image to a 400-pixel card.
> callout tip > Compression is a design decision. A slightly softer image may be better than a sharp image that delays the page.
Reserving space to avoid layout shift
Layout shift happens when content moves after an image loads. Declare width and height, or reserve space with aspect-ratio. The browser can then calculate the image box before downloading the file.
Writing alt text
Alt text describes the image's useful meaning. Mention the subject and action when they matter. Do not repeat nearby captions or write “image of” unless that distinction is important. Decorative images should use an empty alt="".
A review checklist
| Check | Question |
|---|---|
| Crop | Does every breakpoint keep the focal point visible? |
| Delivery | Is the selected file close to the displayed size? |
| Stability | Are dimensions declared? |
| Access | Does the alt text convey the image's purpose? |
Exercise
A desktop image is wide, but its subject is cut off on phones. Which change should you make first?
Show answer
Provide a phone-specific crop with the picture element, then verify its dimensions, alt text, and file size.