# 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.

- Page: https://codethatmoves.com/tools/images/srcset-generator/
- Site: Code That Moves
- Category: Images and files
- Free, runs in the browser, nothing is uploaded
- Last checked: 2026-11-03

## What it does

- Builds srcset with w descriptors from a file pattern such as /images/hero-{w}.{ext}
- Default width ladder from 320 to 1920 px, or a generated one from a minimum, a maximum and a number of files
- Writes the sizes attribute from breakpoint rows: full width, a fixed pixel width, or columns with a gutter, ordered so the first matching condition is the right one
- Density mode writes 1x, 2x and 3x descriptors for an image shown at one fixed CSS width, such as a logo or an avatar
- Copies the markup as HTML, as JSX with React's srcSet and fetchPriority names, or as a next/image element
- Drop the original image to export every width and format, named by your pattern, as one ZIP. JPEG and WebP everywhere, AVIF where the browser can encode it
- Two or more formats give a picture element with one source per format, AVIF first, and the img as the fallback
- Adds width, height, alt, loading, fetchpriority and decoding, and warns about combinations that work against each other
- A table shows the file the browser would pick at eight common viewport widths at 1x, 2x and 3x, and marks the cases where the largest file is still too small
- The whole setup lives in the page address, so you can share it

## How to use it

1. Type the file pattern of your exported images and the widths you have, or generate a ladder.
2. Pick a layout preset or edit the rows: from which viewport width the image is how wide, in vw or px, minus any padding.
3. Check the table for cells marked as too small, then copy the markup as HTML, JSX or next/image.
4. 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

- [MDN: The Image Embed element (img), srcset and sizes](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/img)
- [MDN: Responsive images](https://developer.mozilla.org/en-US/docs/Web/HTML/Guides/Responsive_images)
- [HTML Living Standard: Images (srcset and sizes)](https://html.spec.whatwg.org/multipage/images.html)

## 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.
