Your Responsive Images Still Download at Full Size: Questions About srcset and sizes
Short answer: The browser chooses an image file before your CSS has been applied, so it cannot know how wide the image will be on screen unless you tell it with the sizes attribute. If sizes is missing, the browser assumes the image fills the whole viewport width, and picks a large file even when the picture sits in a narrow column. Write sizes to describe the slot width at each breakpoint, list file widths in srcset with the w descriptor, and check the Network panel to confirm the file picked is close to the displayed width multiplied by the screen density.
What does srcset do by itself?
srcset lists candidate files. With width descriptors it looks like this:
<img src="shop-800.jpg"
srcset="shop-400.jpg 400w, shop-800.jpg 800w, shop-1600.jpg 1600w"
sizes="(min-width: 60rem) 33vw, 100vw"
width="1600" height="1067" alt="Shopfront on Market Street">
Each 400w is the real pixel width of that file. The browser multiplies the slot width by the device pixel ratio, compares the result to the list, and picks a suitable file. Without sizes, the slot width defaults to 100vw, so a three-column gallery on a laptop will fetch an image sized for the full window.
Why does sizes matter if CSS already sets the width?
Because of timing. The browser starts downloading images while it is still reading the HTML, often before the stylesheet arrives and long before layout is complete. It cannot ask "how wide will this end up?" at that moment. sizes is your promise about the layout, written in a form it can read early. If your promise is wrong, the choice is wrong, but nothing breaks visually, so mistakes go unnoticed.
How do I write a correct sizes value?
Walk through your layout, from the widest breakpoint to the narrowest, and write the width the image takes at each. Suppose a blog card image is one third of the container above 60rem, half of it between 40 and 60rem, and the full width below that, with a 1rem page margin:
sizes="(min-width: 60rem) calc((100vw - 4rem) / 3),
(min-width: 40rem) calc((100vw - 3rem) / 2),
calc(100vw - 2rem)"
The browser reads the conditions in order and uses the first that matches, so put the largest breakpoint first. Slight over-estimates are harmless. Large under-estimates make the picture look soft on high density screens.
Which widths should I generate?
Pick steps that are not too far apart. For a content image shown at up to 800 CSS pixels wide, files at 400, 800, 1200 and 1600 pixels cover phones, laptops and dense screens. Going finer than about a 25 percent step rarely repays the extra files. Hero images need larger steps, perhaps up to 2400 pixels for big monitors. Do not upscale small originals to fake a bigger file; it adds weight without detail.
Should I use x descriptors instead?
1x, 2x descriptors suit fixed-size images such as a logo that is always 120 pixels wide. They tell the browser which file to use for a standard or dense screen. For fluid layouts where the width changes, use w descriptors with sizes. You cannot mix the two styles in one srcset.
How do I check what was downloaded?
- Open the page in a desktop browser with the developer tools open.
- Go to Network, filter by Img, tick Disable cache and reload.
- Click an image row and read its received size and the request URL.
- Compare the file's pixel width with the width shown on screen. If an image displays at 360 pixels on a screen with a density of 2, a file near 720 pixels is ideal. A 1600 pixel file means
sizesis wrong or missing. - Resize the window or use the device toolbar, reload at each width and note the file changes.
Remember that browsers may keep using a larger file they already have in cache rather than download a smaller one, which can make results look odd when you resize without clearing.
Does the picture element change any of this?
Use <picture> when you need different crops or formats, for example a tight crop for phones and a wide crop for desktop with media conditions, or modern formats with a fallback. Inside each source you can still use srcset and sizes. For most pictures where only the size changes, a plain img with srcset and sizes is simpler and enough.
Will my CMS or theme do it for me?
Many do. WordPress, for example, adds srcset and a default sizes for images inserted in content, based on the registered sizes. The default sizes guesses that the image fills the content column, which is wrong for cards, grids and sidebars. Check a few page types, not only blog posts. If your theme prints images through custom templates, the attribute may be absent. Shopify and similar platforms provide size filters, and you need to pass the widths in the template.
What about lazy loading and the top image?
loading="lazy" delays fetching images below the fold and is harmless to srcset. Do not lazy-load the main image at the top of the page, because that delays the largest visible element. Keep the width and height attributes on every image so the browser reserves space and avoids a layout jump.
What is the quickest win if I only have an hour?
Check the five heaviest images in the Network panel on a phone-width window, correct the sizes on those templates, and regenerate widths if the smallest file is still too big. That usually removes more weight than any compression plugin.
FAQ
Do I need sizes if every image is full width?
No. When the image really fills the viewport, the default of 100vw is correct.
Can I leave out the src attribute?
Keep it. It is the fallback for browsers that ignore srcset, and it is what search engines and some tools read.
Why does a 2x phone download a 1600 pixel file for a 400 pixel slot?
Because sizes probably says 100vw, so the slot is read as 390 css pixels times 2 plus a safety margin, or the layout has the image wider than you think. Measure the real slot in the inspector.
Are WebP and AVIF affected?
The same rules apply. Offer the same widths in each format inside picture, or serve one modern format with srcset.
If your images are heavier than they should be and you would like them reviewed template by template, contact us through the enquiry page.