01What is Srcset Generator?
Srcset Generator writes the <img> markup for resolution switching. That is the case where you have one picture saved at several widths and want the browser to download the smallest file that still looks sharp. The HTML Living Standard defines how srcset and sizes work together, and this tool fills in both for you. You give it three things. First, a base image URL. Second, the widths you have actually exported, for example 320, 640, 768, 1024, 1280 and 1920. Third, a sizes value that says how wide the image is shown on screen. The widths are cleaned up first. They are sorted and repeats are dropped, because the spec treats two candidates with the same width descriptor as an error. Then each width gets its own URL. By default the tool inserts -<width>w before the file extension in the last path segment. So hero.jpg becomes hero-640w.jpg, and hero.v2.jpg becomes hero.v2-640w.jpg, while the host, query string and fragment stay untouched. If your image CDN resizes on request, put {width} or {w} in the URL instead, like photo.jpg?w={width}&q=80, and the number goes there. The output is a full img tag. It has srcset with w descriptors, your sizes value (100vw if you leave it empty), and an alt placeholder you should replace. Tick the box and you also get loading="lazy". The fallback src is the first width of 1024 or more, or the largest width if none reach 1024. URLs are made safe for an HTML attribute: & becomes &, quotes are escaped, and spaces become %20 so they can't split a candidate. A comma at the very start or end of a URL becomes %2C for the same reason. A worked example. Base URL https://cdn.example.com/images/blog/post-1.webp, widths 320, 640, 960, sizes (max-width: 640px) 100vw, 320px. You get three candidates, post-1-320w.webp through post-1-960w.webp, and a src pointing at the 960w file. Now the limits. The tool only writes markup. It doesn't resize, convert or upload images, and it can't check that hero-640w.jpg exists on your server. It doesn't build <picture> elements for art direction or format switching, and it doesn't output x density descriptors. A base URL with no file name, such as https://example.com or a path ending in /, has nothing to tag. The tool then adds the width as a query parameter, giving https://example.com/?w=300, and keeps any #fragment at the end.
Front-end and theme developers who already have images exported at several widths and want correct srcset and sizes markup without typing every URL. The tool runs entirely in your browser, so your data never leaves your device.
02How to use Srcset Generator
- Enter the Base Image URL, or a URL containing {width} for CDN resizing. The Hero Image and Blog Thumbnail examples fill in sample values.
- List the widths you have files for in Breakpoint Widths (comma-separated).
- Set sizes to how wide the image is displayed, such as 100vw or (max-width: 768px) 100vw, 50vw.
- Tick the lazy loading box only for images below the fold.
- Copy the generated HTML and replace the Descriptive alt text placeholder with a real description.
03Worked examples
- Input:
Base URL https://cdn.example.com/images/blog/post-1.webp, widths 320, 640, 960, sizes (max-width: 640px) 100vw, 320px, lazy loading on - Result:
<img src="https://cdn.example.com/images/blog/post-1-960w.webp" srcset=" https://cdn.example.com/images/blog/post-1-320w.webp 320w, https://cdn.example.com/images/blog/post-1-640w.webp 640w, https://cdn.example.com/images/blog/post-1-960w.webp 960w" sizes="(max-width: 640px) 100vw, 320px" alt="Descriptive alt text" loading="lazy" /> - No width reaches 1024, so the largest one (960) becomes the fallback src.
- Input:
Base URL https://img.example.com/photo.jpg?w={width}&q=80, widths 800 400 400 1200, sizes 100vw - Result:
src="https://img.example.com/photo.jpg?w=1200&q=80" srcset: ...?w=400&q=80 400w, ...?w=800&q=80 800w, ...?w=1200&q=80 1200w - Trimmed. The placeholder is replaced, widths are sorted, the second 400 is dropped, and & is escaped inside the attribute.
- Input:
Base URL /images/team photo.png, widths 640, 768, sizes left empty - Result:
src="/images/team%20photo-768w.png" srcset: /images/team%20photo-640w.png 640w, /images/team%20photo-768w.png 768w sizes="100vw" - Trimmed. Spaces are encoded as %20, and an empty sizes field falls back to 100vw.
- Input:
Base URL https://cdn.example.com/a/hero.v2.jpg?v=3#top, width 480 - Result:
https://cdn.example.com/a/hero.v2-480w.jpg?v=3#top 480w - Only the srcset candidate shown. The last dot marks the extension, and the query string and fragment are kept.
- Input:
Base URL https://example.com/hero (no file extension), width 320 - Result:
https://example.com/hero-320w 320w - Only the srcset candidate shown. With no extension the suffix goes on the end of the last path segment.
04Common use cases
- Writing responsive markup for a blog hero exported at 640, 1280 and 1920 pixels wide from a build script
- Generating srcset for an image CDN that resizes through a query parameter such as ?w={width}
- Checking that a theme's naming scheme, name-640w.jpg, produces the URLs your image pipeline really writes
- Getting a starting img tag for a two-column layout with sizes set to (max-width: 768px) 100vw, 50vw
- Showing a teammate how width descriptors and sizes fit together with a real tag they can edit
- Fixing a hand-written srcset that repeated a width and failed HTML validation
05Tips
- sizes describes your layout, not your files. If it says 100vw but the image sits in a 400px column, phones will download a much bigger file than they need.
- The browser multiplies the slot width by the device pixel ratio. A 400px slot on a 2x screen wants the 800w candidate, so export widths that cover high-density screens.
- Leave lazy loading off for the main image at the top of the page. It is often the Largest Contentful Paint element, and lazy loading delays it.
- Add width and height attributes with the image's intrinsic size after you paste the tag. The browser can then reserve space and avoid layout shift.
- Use {w} as a shorter placeholder if your CDN URL is already long. It works the same as {width}.
06Related concepts
Responsive images, srcset, sizes attribute, Device pixel ratio, Largest Contentful Paint.
Frequently Asked Questions
What is Srcset Generator?
Srcset Generator is a free, browser-based developer tool on AIDToolStack. Generate responsive image srcset attributes for different screen sizes. It requires no installation or sign-up and works entirely in your browser.
Is Srcset Generator free to use?
Yes. No sign-up, no fees and no usage cap.
Does Srcset Generator store my data?
No. It runs in your browser; nothing is uploaded.