FIELD NOTE / IMAGE SYSTEMS

Responsive Images with srcset and sizes

Use srcset and sizes to describe real image candidates and layout slots so browsers can avoid oversized downloads.

01100VISUAL QUALITY / DELIVERY WEIGHT
Device frame containing three measured bars for responsive image candidates

Short answer: srcset lists the image files the browser may choose, while sizes describes the image’s expected layout width before CSS has finished loading. Use width descriptors for responsive layout slots, write sizes from the actual grid, and verify the selected URL at each target viewport. The browser chooses; your markup must give it honest information.

Understand the two inputs

A width-based srcset might offer files at 480w, 800w, 1200w, and 1600w. Those numbers must match the candidates’ intrinsic widths. The sizes attribute then says something like “under 720 pixels of viewport width, this slot is almost the full viewport; otherwise it is about half of a capped content container.” The browser combines that estimate with device pixel density and chooses a candidate.

Without an accurate sizes value, the browser may assume a much larger slot and over-download. The markup can be technically valid while still wasting bytes. Treat sizes as a compact representation of the CSS, not a decoration copied from another component.

Derive sizes from the layout

Inspect the component rather than guessing. If the mobile layout has 20-pixel gutters, its slot might be calc(100vw - 40px). If a desktop grid has two columns inside a 1200-pixel wrapper, the image might occupy roughly 580 pixels rather than 50vw on a wide monitor. Express conditions from narrowest to broadest and end with the default slot.

Revisit the attribute when design changes. A card that moves from three columns to two has a larger slot even if the image component code stays untouched. Responsive-image bugs often appear after layout refactors because the candidate generation and sizes rule were owned by different teams.

Separate resolution switching from art direction

Use one source composition and several widths when the same visual works everywhere. Use picture when mobile requires a tighter crop, a dark-mode asset, or a format source with a fallback. Each source can carry its own media condition, type, srcset, and sizes; the final img remains required as the fallback and the semantic image element.

Do not use art direction to hide essential content. Every branch should communicate the same meaning and share suitable alternative text. Crops need their own visual QA because a focal subject that survives on desktop may be clipped on mobile.

Avoid duplicate downloads

Let the browser’s selection algorithm work. JavaScript that swaps src after the parser discovers an initial image can trigger two requests. Preloading a different candidate from the one selected by srcset can do the same. If a critical responsive image is preloaded, its responsive attributes must match the final markup.

Similarly, do not place a heavy default src beside malformed candidates and assume it will never load. The fallback must be reasonable on its own, and the final HTML should be tested in browsers rather than validated only as a string.

Build a practical candidate ladder

Start with observed slot widths and multiply by the density levels that produce a visible benefit. Merge near-duplicates. Cap the largest output at the useful source width; upscaling does not create detail. For a 360-pixel mobile slot and a 600-pixel desktop slot, candidates around 400, 640, 800, and 1200 pixels may be more useful than a generic library of ten widths. Your numbers should come from your components.

Verify browser decisions

Open a fresh context, set an exact viewport, clear cache, and inspect the request. Record the candidate URL, intrinsic width, rendered width, transfer bytes, and device pixel ratio. Repeat at mobile, laptop, and wide desktop sizes. Resize testing in an already loaded tab can mislead because the browser may keep a larger candidate it has already downloaded.

Responsive images do not automatically make an image fast. They make the browser capable of choosing well. The quality of that choice depends on accurate candidates, truthful layout hints, a sensible format strategy, and a test that observes the network result.

Field checklist

  • List candidate widths as their true intrinsic widths.
  • Translate CSS layout rules into a realistic sizes value.
  • Use picture only when format or composition needs a branch.
  • Keep an img fallback with useful alt text.
  • Verify selections at clean-cache viewport tests.

Continue the workflow

Primary references