How to use the srcset generator
- Enter the File name pattern (
{w}= width), for example/images/hero-{w}.jpg. - List the Widths you have files for, separated by commas or spaces.
- Write the sizes value and the Alt text.
- Enter the Intrinsic width and Intrinsic height so the browser can reserve space. Use 0 to leave them out.
- Keep
<picture>with AVIF and WebP sources ticked if you have those files, and Lazy-load for images below the first screen. - Copy the code.
What it does and when to use it
A phone and a 4K monitor should not download the same image. With srcset you list the same picture at several widths, using the w unit, and with sizes you say how wide it will be displayed. The browser combines that with the screen’s size and pixel density and fetches the smallest file that still looks sharp. A picture element goes further and lets the browser choose a newer, smaller format: AVIF first, then WebP, then the original JPEG or PNG.
Use this tool for hero banners, article images and product photos that appear at different sizes across devices. For a single image with no variants, the HTML Image Tag Generator is simpler. To make the resized files, use the Image Resizer and then the Image Compressor.
How it works
The widths are cleaned up first: duplicates and non-numbers are removed and the list is sorted from small to large. For each width, {w} in the pattern is replaced, giving entries such as /images/hero-480.jpg 480w. For the AVIF and WebP sources, the extension at the end of the pattern is swapped for .avif or .webp, so your files must follow the same naming. The img gets alt, the intrinsic size and, when ticked, loading="lazy" decoding="async". The code is built in your browser.
Worked examples
Plain img, default settings without picture. The srcset lists all five widths: /images/hero-480.jpg 480w, /images/hero-800.jpg 800w, /images/hero-1200.jpg 1200w, /images/hero-1600.jpg 1600w, /images/hero-2400.jpg 2400w. The plain src is /images/hero-800.jpg, the first width of at least 800.
With picture. The same settings give two sources before the img:
<source type="image/avif" srcset="/images/hero-480.avif 480w, /images/hero-800.avif 800w, …" sizes="(max-width: 700px) 100vw, 700px">
<source type="image/webp" srcset="/images/hero-480.webp 480w, /images/hero-800.webp 800w, …" sizes="(max-width: 700px) 100vw, 700px">
Messy widths. Pattern /img/card-{w}.png with widths 600 300 600 gives srcset="/img/card-300.png 300w, /img/card-600.png 600w": sorted, with the duplicate removed.
No placeholder. A pattern without {w}, such as /img/card.png, returns the message “Put {w} in the file name pattern where the width goes, for example photo-{w}.jpg.”
Limits and tips
- Every file listed must exist. A missing width shows as a broken image only on the devices that pick it.
- Do not lazy-load the main image at the top of the page; untick Lazy-load for it.
- The pattern’s extension must be at the very end, without a query string, for the AVIF and WebP names to be correct.
Frequently asked questions
Does this tool resize my images?
How do I write the sizes attribute?
Which widths should I list?
Why does the picture element repeat the img?
Which file is used as the plain src?
How do we know nothing is uploaded? Test it yourself on the privacy proof page.