srcset lists several versions of an image with their real widths, and sizes tells the browser how wide the image will be displayed. The browser combines the two with the screen’s pixel density and downloads the smallest file that still looks sharp. Get sizes wrong, or leave it out, and the browser assumes the image fills the whole screen, which usually means downloading a much bigger file than needed.
This guide explains both attributes with worked examples for the three most common layouts, when to use <picture> instead, and how the newer sizes="auto" fits in.
Last checked: October 2026.
Key takeaways
- Use width descriptors (
800w) insrcsetfor images that change size with the layout. - Write
sizesto match your CSS: how wide the image is at each breakpoint. - Use density descriptors (
2x) only for images shown at a fixed size, such as logos. - Keep
widthandheight, and don’t lazy-load the main image at the top of the page. sizes="auto"works for lazy-loaded images in Chrome, Edge and Firefox, with a fallback list for other browsers.
How srcset and sizes work together
<img
src="/img/hero-1200.webp"
srcset="/img/hero-480.webp 480w,
/img/hero-800.webp 800w,
/img/hero-1200.webp 1200w,
/img/hero-1600.webp 1600w,
/img/hero-2400.webp 2400w"
sizes="(max-width: 800px) 100vw, 800px"
width="2400" height="1350"
alt="Describe the image">
- srcset lists each file and its actual width in pixels, written with a
w. - sizes says how wide the image will be shown: the full viewport width on screens up to 800px wide, and 800px on anything wider.
- src is the fallback for very old browsers.
The browser multiplies the display width by the screen’s pixel density and usually picks the smallest file at or above that number. On a 390px-wide phone at 3× density, the image is shown at 390px, so it needs about 1,170 pixels and the browser downloads the 1,200px file. On a desktop with a 2× screen, the image is 800px wide and needs 1,600 pixels.
The final choice is up to the browser. It may use a larger file it already has in its cache, or a smaller one on a slow connection, which is why srcset is a list of options rather than a set of rules. If you need to force a particular image under particular conditions, that is a job for <picture>.
Writing sizes for common layouts
sizes should describe your CSS, not your images. Read it as “under this condition, the image is this wide”, checked from left to right; the last value has no condition and applies otherwise.
| Layout | sizes value |
|---|---|
| Full-width hero | 100vw |
| Article column, max 760px wide | (max-width: 800px) 100vw, 760px |
| Three-column grid that stacks on phones | (max-width: 600px) 100vw, (max-width: 1000px) 50vw, 33vw |
| Sidebar image, always 300px | 300px |
Allow for padding where it matters. If an article column has 20px of padding on each side on phones, calc(100vw - 40px) is more accurate than 100vw, though the difference is rarely worth extra complexity.
Width descriptors or density descriptors?
For an image shown at a fixed size, such as a 200px logo, you don’t need sizes at all. List versions by screen density instead:
<img src="/img/logo-200.png"
srcset="/img/logo-200.png 1x, /img/logo-400.png 2x"
width="200" height="60" alt="Company name">
For anything that resizes with the layout, use width descriptors and sizes. Mixing the two in one srcset isn’t allowed.
srcset or the picture element?
| Use | When |
|---|---|
<img srcset sizes> | Same image, different sizes. The browser chooses. |
<picture> with type | Different formats, such as AVIF with a WebP or JPEG fallback. |
<picture> with media | A different crop on small screens (art direction). You choose. |
You can combine them: each <source> inside <picture> takes its own srcset and sizes. The WebP vs AVIF vs JPEG guide shows the format version.
sizes=”auto” for lazy-loaded images
Images with loading="lazy" don’t load until the layout is known, so the browser can measure them itself. sizes="auto" tells it to do that:
<img loading="lazy"
srcset="card-400.webp 400w, card-800.webp 800w, card-1200.webp 1200w"
sizes="auto, (max-width: 600px) 100vw, 33vw"
width="1200" height="800" alt="…">
It’s supported in Chrome and Edge from version 126 and Firefox from version 150, with only partial support in Safari so far. Browsers that don’t understand auto use the list after it, so always include one. WordPress has added auto to lazy-loaded images automatically since version 6.7. It only works with loading="lazy".
Mistakes that waste data
- Leaving out sizes with width descriptors. The browser assumes
100vwand downloads a full-screen image for a small card. - Lazy-loading the hero image. It delays your Largest Contentful Paint. Load it normally, and consider
fetchpriority="high"on it. - Missing width and height, which lets the page jump as images load.
- Too many or too few widths. Five or six between about 480px and 1,920px covers most layouts; add 2,400px or 2,560px for full-width images on large high-density screens.
- Upscaled files. A 2,400w entry made from an 1,800px original adds bytes and no detail.
Tip: Not sure what widths you need? Measure the image at your widest and narrowest layouts, multiply by 2 for high-density screens, and fill the gaps in between. The guide to image sizes has typical numbers for heroes, articles and thumbnails.
Generate the files and the HTML
The srcset generator does the tedious part. Drop in your largest image, tick the widths, describe the layout (full width, content column or grid), and it creates every file as WebP, AVIF or JPEG and writes the srcset, sizes or <picture> markup. Everything happens in your browser. For a placeholder to show while those images load, see the blur placeholder generator.
Sources: Can I use: sizes=”auto”, WordPress 6.7: auto sizes for lazy-loaded images.

