srcset & sizes Generator
Describe your image files and your layout, get a correct srcset and sizes string with img or picture markup, export the files themselves, and see which file each phone and desktop would load.
Last checked
Image files
Layout (sizes)
| Viewport from | Image width | Minus px | Remove |
|---|---|---|---|
| Otherwise |
Attributes
Markup
sizes: (min-width: 1280px) 1200px, (min-width: 768px) calc(50vw - 32px), calc(100vw - 32px)
sizes (min-width: 1280px) 1200px, (min-width: 768px) calc(50vw - 32px), calc(100vw - 32px)
<picture>
<source
type="image/avif"
srcset="/images/hero-320.avif 320w, /images/hero-480.avif 480w, /images/hero-640.avif 640w, /images/hero-768.avif 768w, /images/hero-960.avif 960w, /images/hero-1280.avif 1280w, /images/hero-1600.avif 1600w, /images/hero-1920.avif 1920w"
sizes="(min-width: 1280px) 1200px, (min-width: 768px) calc(50vw - 32px), calc(100vw - 32px)"
/>
<source
type="image/webp"
srcset="/images/hero-320.webp 320w, /images/hero-480.webp 480w, /images/hero-640.webp 640w, /images/hero-768.webp 768w, /images/hero-960.webp 960w, /images/hero-1280.webp 1280w, /images/hero-1600.webp 1600w, /images/hero-1920.webp 1920w"
sizes="(min-width: 1280px) 1200px, (min-width: 768px) calc(50vw - 32px), calc(100vw - 32px)"
/>
<img
src="/images/hero-960.jpg"
srcset="/images/hero-320.jpg 320w, /images/hero-480.jpg 480w, /images/hero-640.jpg 640w, /images/hero-768.jpg 768w, /images/hero-960.jpg 960w, /images/hero-1280.jpg 1280w, /images/hero-1600.jpg 1600w, /images/hero-1920.jpg 1920w"
sizes="(min-width: 1280px) 1200px, (min-width: 768px) calc(50vw - 32px), calc(100vw - 32px)"
width="1920"
height="1080"
alt=""
loading="lazy"
decoding="async"
/>
</picture>- The widest case needs 3600 px; the largest file is 1920w, so it will be upscaled there.
- Write the alt text, or keep alt="" only for a decorative image.
Make the files
Choose the original and get every width and format as a ZIP, named by the pattern.
Which file the browser picks
| Viewport | Slot | 1x | 2x | 3x |
|---|---|---|---|---|
| 360 | 328 | 480w | 768w | 1280w |
| 390 | 358 | 480w | 768w | 1280w |
| 412 | 380 | 480w | 768w | 1280w |
| 768 | 352 | 480w | 768w | 1280w |
| 1024 | 480 | 480w | 960w | 1600w |
| 1280 | 1200 | 1280w | 1920w | 1920w |
| 1440 | 1200 | 1280w | 1920w | 1920w |
| 1920 | 1200 | 1280w | 1920w | 1920w |
How to use it
- Type the file pattern of your exported images and the widths you have, or generate a ladder.
- Pick a layout preset or edit the rows: from which viewport width the image is how wide, in vw or px, minus any padding.
- Check the table for cells marked as too small, then copy the markup as HTML, JSX or next/image.
- Optionally choose the original image and press Make files to get every width and format in one ZIP.
What it checks and why
srcset lists the image files with their real widths, written as 480w, 800w and so on. MDN says the width descriptor "must match the intrinsic width of the referenced image". sizes tells the browser how wide the image will be on the page before any CSS has loaded. It is a list of media conditions and lengths; the browser takes the first condition that matches, and the last entry has no condition. Without sizes the browser assumes 100vw, the full viewport width, which on a desktop often means a far too large file.
The browser divides each file width by the slot width from sizes to get its pixel density, and picks a file that fits the screen's device pixel ratio. A 400 px wide slot on a 2x phone needs about 800 image pixels. The table in this tool models that choice as the smallest file that covers slot × DPR. The HTML spec leaves the final pick to the browser, so a browser can take a smaller file on a slow connection or reuse a larger one it already has in the cache.
sizes values are lengths such as 50vw, 640px or calc(50vw - 32px). MDN notes that percentages are not allowed and that em is relative to the root font size, not to the image. Media conditions describe the viewport, not the image's container, so a sidebar or a max-width container has to be written out as numbers. Do not mix w and x descriptors in one srcset.
With several formats, picture lets the browser take the first source whose type it supports, so AVIF goes first, then WebP, and the img with JPEG is the fallback. For the main image above the fold, the LCP image, use loading="eager" and fetchpriority="high". For images further down, loading="lazy" saves the download until the image is close to the viewport.
Specs and sources
Limits
- The pick table is a model of the usual choice. Real browsers also weigh the cache, zoom, and data saver settings, and Chromium may round to a nearby file.
- The exported files are encoded by the browser's canvas, which writes no AVIF in most browsers and strips colour profiles and metadata. Use a build tool (sharp, Squoosh) when you need AVIF or finer control. Widths larger than the original are left out, not upscaled.
- next/image makes its own width ladder from one source file, so only the source, size, sizes and loading hints carry over. With output: "export" it needs images.unoptimized or a custom loader.
- Media conditions use min-width in px. If your CSS uses em breakpoints, convert them with your root font size. sizes="auto" for lazy images is not written by the tool, because browser support is still partial.
- The sizes string is only as good as your layout numbers. Measure the image's rendered width in DevTools at a few widths to check it.
Questions
- What is the difference between srcset and sizes?
- srcset lists the files and their widths. sizes says how wide the image is shown at each viewport width. The browser needs both to pick a file before it has the CSS.
- What happens if I leave out sizes?
- With w descriptors the browser assumes 100vw, so an image in a three-column grid on a desktop loads a file sized for the whole screen.
- Should I use w or x descriptors?
- Use w with sizes when the image changes width across layouts. Use 1x and 2x when it is always shown at the same CSS size, such as a logo or an avatar; switch the tool to 1x 2x 3x for that. Do not mix them in one srcset.
- Why does the browser load a bigger file than I expected?
- Usually the screen has a 2x or 3x pixel ratio, sizes is missing or too large, or a larger file is already in the cache. Check the rendered width and the DPR in DevTools.
- Do I still need width and height with srcset?
- Yes. They give the aspect ratio, so the browser reserves space before the file arrives and the page does not shift.