Web design and digital-business ideas grounded in real tasks.

Responsive images need a realistic sizes value as well as a srcset

The same editorial webpage shown on a phone and laptop with differently sized landscape photographs.
AI-generated photographic illustration; not documentary photography.

Offering three image files does not tell the browser how wide the image will appear in the layout. With width descriptors in srcset, the sizes attribute supplies that missing hint. If the hint is unrealistic, the browser may choose a larger resource than the design needs.

The MDN responsive-images guide explains how srcset candidates and sizes work together. The browser also considers factors such as device pixel density; the selection is not simply “small screen equals smallest file.”

Describe the slot your CSS actually creates

Imagine an image that occupies the viewport width minus 32 pixels on small screens, then sits in a 560-pixel article column. A corresponding illustrative value could be sizes="(max-width: 600px) calc(100vw - 32px), 560px". That value is useful only if the real CSS follows those dimensions.

Changing the attribute does not itself resize the displayed image. The layout still comes from CSS and the element’s sizing rules. Update the hint when the layout changes rather than leaving an old value copied from another component.

Check what the browser selected

Use developer tools to inspect the rendered width and the image element’s currentSrc. Test a narrow viewport and a wider one with a fresh load, taking caching into account. Also look at the downloaded file’s dimensions and transfer size.

A high-density display may reasonably need a source wider than the CSS slot. Conversely, a very wide source can still be unnecessarily heavy if the original was poorly compressed. Candidate selection and image encoding are separate parts of the performance work.

Preserve the image’s meaning

Supply appropriate alternative text and intrinsic width and height where possible. If the composition itself must change on a small screen, investigate art direction with the picture element instead of treating resolution switching as a crop instruction. Test the resulting page visually as well as reading the network numbers.