b2KIT

Responsive Image Srcset Generator

Build responsive image srcset and sizes attributes for optimal image delivery across screen sizes.

Tested tool guide Tested browser tools Checked August 16, 2026

What Responsive Image Srcset Generator does, with a checked example

A generator that turns your image variants into the srcset and sizes attributes of an img tag. You enter each file with its real pixel width and describe how wide the image renders at each breakpoint; the tool returns attribute markup you can paste straight into HTML or a template. The one thing most people get wrong: srcset without a matching sizes. When sizes is missing, browsers assume the image fills the full viewport width, so a small card image on a big monitor downloads the largest file you published. Sizes is what makes the width descriptors meaningful.

Worked example

A concrete input and expected output from the current implementation.

Input

Image variants: hero-400.jpg, hero-800.jpg, hero-1600.jpg. Layout: full viewport width on screens up to 900px wide, half the viewport width on larger screens.

Expected output

<img src="hero-800.jpg"
     srcset="hero-400.jpg 400w, hero-800.jpg 800w, hero-1600.jpg 1600w"
     sizes="(max-width: 900px) 100vw, 50vw"
     alt="Hero image">

On a 375px phone at device pixel ratio 1, the first sizes rule applies, the slot is 100vw, about 375px, and the browser picks the smallest candidate at or above that width: hero-400.jpg. On a 1440px monitor the default rule applies, the slot is 50vw, about 720px, and it picks hero-800.jpg. The src value is the fallback for browsers without srcset support.

How the result is produced

1

Width and density descriptors

Each srcset entry pairs a URL with one descriptor. A w descriptor declares the file's intrinsic pixel width; a density descriptor (1x, 2x) declares a fixed scale for a slot whose rendered width never changes. Width entries must be listed in ascending order and the two types cannot be mixed in one srcset. The browser treats the declared width as fact, so it must match the actual file.

2

How sizes drives the choice

The sizes attribute lists media-condition and width pairs; the first condition true for the viewport gives the slot, the CSS pixel width the image will occupy. The browser divides each candidate's declared width by the slot width and picks the smallest candidate at or above the device pixel ratio, falling back to the largest. Without sizes the slot defaults to 100vw, and conditions test viewport width, never container width.

Good uses

  • Publishing full-width hero or article images that scale from phone to desktop, so a mobile reader gets a 400px file instead of the 2000px original.
  • Producing paste-ready markup for a fixed set of build-resized variants, such as 480, 800, 1200 and 1600, when your templates or CMS take raw HTML.
  • Building a srcset for fixed-size slots like avatars or product thumbnails using 1x and 2x entries, where the rendered width never changes with the viewport.

Limits and checks

  • The w number must be the file's true pixel width. The browser does not verify it: declare 800w on a 1200px file and selection behaves as if the file were 800px wide, giving a blurry image or wasted bytes.
  • Omitting sizes is not a no-op, the default slot is 100vw, so the output is only optimal when your sizes matches the width the image actually occupies, including padding and gutters. The generator computes attributes; it cannot know your layout.
  • The tool emits markup, not image files. The width variants must already exist, and a srcset whose files were never generated falls back to src without telling you.

Common questions

When should I use w descriptors instead of 1x/2x?

Use 1x/2x when the image renders at a fixed CSS size in every layout, like an avatar. Use w descriptors with sizes when the rendered width changes with the viewport, which is most content images. The two cannot be mixed in one srcset, and without sizes, w descriptors are evaluated against a default 100vw slot.

If I resize the window, does the browser re-download the image?

No. The candidate is selected when the image is fetched, and resizing the viewport after load does not trigger a new selection or download in normal use. Test different widths by reloading at different window sizes, or use the responsive mode in browser devtools.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools