Zero Signup ToolsFree browser tools

Developer Tools

HTML srcset Generator

Build a responsive HTML image tag with srcset, sizes, and a picture element fallback. Width and density descriptors, AVIF, WebP, and JPEG sources.

Mode

Pick a srcset flavor

Width descriptors pair with sizes for responsive layouts. Density descriptors are simpler: the browser picks based on the device pixel ratio.

Filename pattern

URL template for each variant

Use {w} for the width number and {ext} for the extension. Root-relative (/images/...) and full URLs (https://...) both work.

The src attribute uses this width. Old browsers that ignore srcset will load this file.

Widths

Variants in the srcset

7 widths.

Order does not matter; duplicates are removed; the srcset is emitted in ascending order.

Presets

Sizes attribute

How wide is the image at each viewport?

Each rule pairs a media query with the rendered width. The last rule with an empty media query is the default and goes last.

Presets

sizes="(max-width: 600px) 100vw, 640px"

Picture element

Add format fallbacks (AVIF then WebP then JPEG)

Each enabled source produces a <source> row with its own srcset and a type hint, plus the <img> falls back to the JPEG or PNG file you picked above.

Img attributes

Alt text and loading hints

Leave blank only for purely decorative images. Empty alt is still emitted as alt="".

loading

decoding

fetchpriority

Output

<img> tag

<img
  src="/images/hero-1280.jpg"
  srcset="/images/hero-320.jpg 320w, /images/hero-480.jpg 480w, /images/hero-640.jpg 640w, /images/hero-960.jpg 960w, /images/hero-1280.jpg 1280w, /images/hero-1600.jpg 1600w, /images/hero-1920.jpg 1920w"
  sizes="(max-width: 600px) 100vw, 640px"
  alt="Descriptive alt text for screen readers"
  loading="lazy"
  decoding="async"
>

Attribute values

srcset only

Drop this into an existing <img> tag.

/images/hero-320.jpg 320w, /images/hero-480.jpg 480w, /images/hero-640.jpg 640w, /images/hero-960.jpg 960w, /images/hero-1280.jpg 1280w, /images/hero-1600.jpg 1600w, /images/hero-1920.jpg 1920w

sizes only

(max-width: 600px) 100vw, 640px

Validation

No issues detected

The output is well-formed. Paste it into your page and ship.

Preview

Live render of the fallback URL

Only enable if the URLs in your pattern are reachable from this page (full https URLs or paths to files on the current domain).

srcset reference

Width vs density descriptors at a glance

w descriptor

Each entry declares the natural width of the file. Pair with a sizes attribute so the browser knows the rendered width at the current viewport, then it picks the smallest file that is at least as wide as needed times the device pixel ratio.

srcset="a.jpg 640w, b.jpg 1280w"

sizes="(max-width: 600px) 100vw, 640px"

x descriptor

Each entry declares a device pixel ratio. Use when the image has a single rendered size and you want a sharp version on high-DPI screens. No sizes attribute is needed.

srcset="a.jpg 1x, a@2x.jpg 2x, a@3x.jpg 3x"

sizes

Comma-separated list of (media query) width pairs. The last entry with no media query is the default. Widths can be any CSS length: 100vw, 50vw, 480px, calc(50vw - 1rem).

<picture> element

Wraps the <img> in one or more <source> rows with type hints. Use to serve AVIF and WebP to modern browsers while keeping a JPEG or PNG fallback for older clients.

Tips

Common gotchas

  • Always set sizes when using w descriptors. Without it the browser uses 100vw and may pick a much larger file than the layout needs.
  • Order does not matterinside the srcset value. Browsers sort entries before picking.
  • w descriptors must be unique.Two entries with the same width is a syntax error in the spec.
  • fetchpriority="high"on the LCP image can shave hundreds of milliseconds off Largest Contentful Paint.
  • loading="lazy"is ignored on the first image in the viewport in modern browsers, so it is safe to set everywhere.
  • type hints in <source>let the browser skip downloading the source declaration entirely when it cannot decode that format.

How to use

  1. Pick a mode at the top: Width descriptors for layouts that change with the viewport, or Density descriptors for a single rendered size on high-DPI screens.
  2. Enter a filename pattern with {w} and {ext} tokens, e.g. /images/hero-{w}.jpg. The fallback width sets the file that goes into the src attribute for older browsers.
  3. List the widths or densities you want in the srcset. Use a preset to load the common 7-step ladder, WordPress sizes, or Tailwind breakpoints in one click.
  4. Build the sizes attribute with a preset (full width, half on desktop, three-column grid) or add custom media-query rules by hand. Skip this in density mode.
  5. Optionally tick Picture element and enable AVIF, WebP, or PNG sources to add format fallbacks. The output emits sources in the correct probe order.
  6. Set the alt text, loading, decoding, and fetchpriority attributes, then read the validation panel for any warnings before pasting the generated tag into your template.

About this tool

HTML srcset Generator builds responsive image markup that is ready to paste into any HTML, JSX, or template file. The tool covers both srcset flavors the spec defines. Width descriptors (the 320w, 640w, 1280w form) pair with a sizes attribute so the browser knows the rendered width at each viewport and can pick the smallest file that satisfies the layout times the device pixel ratio; this is the right tool for hero images, article media, and any layout where the rendered size changes with the viewport. Density descriptors (the 1x, 2x, 3x form) target a single rendered size and let the browser pick a sharper file on high-DPI screens without a sizes attribute. A filename pattern with {w} and {ext} tokens expands into every variant from a single template, so /images/hero-{w}.jpg yields hero-320.jpg, hero-640.jpg, hero-1280.jpg, and the rest in one step. Width presets cover the common 7-step ladder (320 to 1920), WordPress core sizes, Tailwind breakpoints, a tight 4-step set for hero images, and a thumbnail set. The sizes builder ships with presets for the most common layouts (always full width, full on mobile then a fixed max on desktop, half-width on desktop, three-column grid, fixed pixel width) and lets you add and remove media-query rules by hand. A picture-element toggle adds AVIF, WebP, and JPEG sources with type hints in the correct probe order, so modern browsers download the smallest format and older clients fall back gracefully. Img-tag attributes are first-class: alt text for screen readers, loading set to lazy or eager, decoding set to async or sync, and fetchpriority set to high for the LCP image. Validation surfaces the issues that quietly break responsive images in production: a width-descriptor srcset without a sizes attribute (the silent 100vw default), a single-width srcset that defeats the whole feature, a missing {w} token in the filename pattern, duplicate width entries, and an empty alt attribute on a non-decorative image. A live preview renders the fallback file using the URL the generator produced, and a copy button puts the full tag, the picture element, the srcset value, or the sizes value straight on your clipboard. Useful for Core Web Vitals work, content management system templates, blog post bodies, marketing pages, and any place an image needs to look sharp on a phone and a 4K screen without the browser downloading more bytes than the layout needs. Everything runs in your browser. Nothing you type is uploaded, logged, or shared.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools