OOmnistu

Blog / Web & Ecommerce

Web & Ecommerce

Responsive images with srcset and sizes: sharp on every screen without wasting data

Understand how srcset and sizes give browsers image choices and what to check when matching files to different displays.

OOmnistu
Reviewed 2026-11-16 · 4 min read

One image file cannot be ideal for a small phone, a high-density laptop and a large monitor. web.dev's Learn Images module gives the browser a choice of files and lets it pick. We read the "Descriptive syntaxes" page in full on 15 November 2026. Claims below come from it unless marked as ours.

The idea: describe, don't instruct

web.dev says srcset is not a way to swap images at set breakpoints or replace one image with another. Each candidate is the same picture, same crop and aspect ratio, at a different size. You describe the candidates and how the image will appear, and the browser decides using factors you cannot all know: viewport, display density, user preferences, bandwidth. The page stresses that "2x" says "this file suits a 2x display", not "use this on 2x displays".

Density with x descriptors

Device pixel ratio (DPR) is physical pixels divided by CSS pixels. web.dev's example: a 400px-wide image fills a 400px slot on any screen, but a DPR 2 display needs at least 800 pixels of real width for it to look sharp. A DPR 1 screen gets nothing from the larger file except slower loading. The page cites Matt Hobbs data that about 18% of GOV.UK sessions in November 2022 reported DPR 1: one site and period, not a general rule.

With x, you list candidates like a 2x file in srcset, with a regular src as the fallback. Browsers without srcset support ignore the attribute and load src.

Widths with w descriptors

The w syntax gives each file's inherent width, for example "small.jpg 600w, large.jpg 1200w". It does not say how big the image appears, so you add sizes.

Telling the browser the layout with sizes

Browsers request images early, before stylesheets are applied, so they know the viewport size, display density and preferences but not your layout. sizes is your description of the rendered width, relative to the viewport. Example from the page: "80vw" means the image will take 80% of the viewport.

How the browser reasons (web.dev's worked example): at a 1000px viewport, 80vw is 800px. Candidates of 600, 1200 and 2000 pixels give ratios of 0.75, 1.5 and 2.5. The 600 file is dropped because it would need upscaling; a DPR 1 device gets the 1200 file, a DPR 2 device the 2000 file. At a 600px viewport (480px slot) the same markup yields ratios of 1.25, 2.5 and about 4.17, so a DPR 1 device gets the small file and a DPR 2 device the medium one.

sizes can mix units with calc(), for example full width minus margins. For layouts that change, it takes comma-separated media conditions that are checked first-match: the browser stops at the first matching condition, and a last value with no condition is the default.

The browser has the last word

The HTML specification's selection algorithm is deliberately vague, so you cannot know for certain which file will be chosen. web.dev says this is by design: density alone does not reflect bandwidth (a fast laptop on a metered connection, for example). It also says that in most browsers an image with srcset or sizes will not request a smaller file than one already cached, but will request a new one if the viewport grows enough to need it. Because all files show identical content, a different choice does not break the page.

Automate it

web.dev says srcset is a clear case for automation (task runners, bundlers, image CDNs or CMS features), and sizes is harder because it depends on the rendered layout. It names respImageLint for checking sizes values and Lazysizes for generating them in JavaScript. We have not tested either.

What to ask your developer (our suggestions)

  1. Export or generate each important image at several widths.
  2. Use srcset with w values and a sizes attribute that matches the real layout.
  3. Keep width and height attributes to avoid layout shift.
  4. Do not lazy-load the main above-the-fold image (see our lazy-loading guide).
  5. Check a few pages in browser developer tools to see which file loads at different widths.

Limits

One web.dev page, read in full. The picture element (art direction), image formats and the CMS and framework pages in the same module were not read. No fixed saving is promised: it depends on your images and visitors. The tools named above were not tested.

By Omnistu.

Sources

Previous
Progressive web app or native app? A decision guide