Glossary

srcset

The srcset attribute lists several files for one image, each labelled with its width or its pixel density, so the browser can pick the one that suits the viewport and screen it is rendering on. It only works with the sizes attribute alongside it: srcset says which files exist, sizes says how wide the image will be rendered, and without the second the browser assumes the image spans the full viewport and picks the largest candidate nearly everywhere.

Width descriptors and density descriptors

A width descriptor labels each candidate with the intrinsic width of the file, which is what lets the browser reason about it against a rendered size.

A density descriptor labels each candidate with the screen density it targets, which suits an image rendered at a fixed size.

The two cannot be mixed in one list, and mixing them makes the whole attribute invalid.

Width descriptors are the general case and require sizes; density descriptors do not, because the rendered size is fixed by definition.

A list with one candidate is a declaration with no choice in it, which is the shape a build tool sometimes produces by accident.

Why sizes is not optional in practice

The specification's default for sizes is the full viewport width, which is correct for a hero image and wrong for almost everything else.

An image rendered at a third of the width therefore has a file about three times wider than needed selected on every screen.

The attribute exists precisely because the browser chooses before the layout is computed, so it cannot know the rendered width by itself.

Writing it means describing the rendered width at each breakpoint, which has to track the CSS rather than being guessed.

Which is the real maintenance cost of responsive images: a layout change silently invalidates the sizes values.

How the browser chooses

It computes the width the image will occupy from sizes, multiplies by the device density, and picks a candidate at least that wide.

It may pick a larger or smaller one based on its own heuristics — a saved-data preference, a slow connection, an already-cached candidate.

Which means a specific choice is not guaranteed and does not need to be: the point is offering a real range.

Candidates the browser never picks cost nothing, since only the chosen file is fetched.

An invalid attribute is discarded entirely and the base source is used, so a syntax error costs the whole mechanism rather than one candidate.

When not to use it

For an image rendered at a fixed size regardless of viewport — an icon, a logo, an avatar. There is nothing to choose between.

For an image that needs a different crop at different widths, which is art direction and belongs to the picture element instead.

For format fallback, which also belongs to the picture element or to server-side negotiation.

Adding it where it is not needed is markup with no effect, and its absence there is not reported as a defect.

How it is observed

The srcset syntax is validated, and the sizes attribute is read and checked against the layout information available.

The intrinsic dimensions of the file really served are compared with the space the image occupies, which is what surfaces an oversized selection.

Width and height attributes are checked separately, since their absence causes layout shift regardless of which candidate is chosen.

Which candidate a given browser selects depends on its own state, so what is validated is that a real choice was offered.

Frequently asked questions

Why does my srcset not reduce any bytes?
Almost certainly a missing sizes attribute. Without it the browser assumes the image spans the viewport and selects the largest candidate on nearly every screen.
Can I mix width and density descriptors?
No. Mixing them makes the attribute invalid, and an invalid srcset is discarded entirely — the browser falls back to the base source.
Does every image need one?
No. An image rendered at a fixed size has nothing to choose between, and its absence there is correct rather than a gap.

Sources

Related

VeriFixScan crawls a site and applies its checks to every page it reaches, keeping the evidence behind each finding. Scanning one website is free.

Scan a website