b2KIT

Picture Element Generator

Generate HTML picture elements with source sets for art direction and format switching across breakpoints.

Tested tool guide Tested browser tools Checked August 16, 2026

What Picture Element Generator does, with a checked example

This tool assembles the markup for the HTML picture element. You supply the image files you have per format and per breakpoint, and it returns the picture block that serves them: a source element for each combination, ordered so the browser can pick one, with a closing img as the fallback. The thing people most often get wrong: the browser does not weigh your sources and choose the best. It walks the list from top to bottom and takes the first source whose media query matches and whose type it can decode, so the order the generator produces is what decides which file actually renders.

Worked example

A concrete input and expected output from the current implementation.

Input

1200px and wider: banner-1200.webp, banner-1200.jpg. Below 1200px: banner-800.webp, banner-800.jpg. Alt text: Product launch banner.

Expected output

<picture>
  <source media="(min-width: 1200px)" srcset="banner-1200.webp" type="image/webp">
  <source media="(min-width: 1200px)" srcset="banner-1200.jpg" type="image/jpeg">
  <source srcset="banner-800.webp" type="image/webp">
  <img src="banner-800.jpg" alt="Product launch banner">
</picture>

Each breakpoint pairs the newer format first, so browsers that can decode WebP never download the JPEG. The last source has no media query, so it serves every viewport below 1200px, and the img element is the final fallback for browsers without picture support while carrying the alt text.

How the result is produced

1

First match wins, in document order

The browser scans the source elements top to bottom and selects the first one whose media attribute evaluates to true and whose type attribute names a format it can decode. Once one source matches, nothing below it is consulted. With min-width queries that means listing the largest breakpoint first, and it means an unconditional source must come after every breakpoint source or it will swallow them all.

2

Type-based format negotiation

Each source's type attribute tells the browser which container format the file uses - image/webp, image/avif, image/jpeg - and a browser skips a source whose type it does not support without downloading the file. The img element at the end is not a suggestion: browsers without picture support render it directly, and it is where alt text and the guaranteed-valid default src live.

Good uses

  • Switching to AVIF or WebP for browsers that support them while older ones get the JPEG, with no server-side negotiation or user-agent sniffing.
  • Art direction: a wide landscape crop on desktop and a square or portrait crop of the same subject on phones, where a single srcset image scaled down would waste bandwidth and crop badly.
  • Generating the boilerplate markup when an image pipeline exports ready-sized variants and you want copy-paste HTML instead of writing the block by hand each time.

Limits and checks

  • Order decides which file loads. If a format source without a media attribute sits above a breakpoint source, every viewport matches it first and the art direction never happens. Re-read the order after any edit.
  • Width descriptors without sizes. If your sources use w descriptors (banner-1200.webp 1200w), the block needs a sizes attribute on the source or the img; without one, browsers assume 100vw and can download a file much larger than the rendered size.
  • The generator cannot verify files. The output is assembled from the URLs and alt text you typed; a typo or a missing file produces markup that looks right and renders a broken image. Confirm each path in the Network tab, which is also the only reliable way to see which source the browser actually selected.

Common questions

The browser will pick the source that best matches my viewport, right?

No. It takes the first source in document order whose media query matches and whose format it supports, and stops there. With min-width queries, list breakpoints from largest to smallest. If you would rather order them ascending, rewrite the queries as max-width with the smallest first. Either scheme works; mixing them is where surprises come from.

Why is the img element still there if every browser I target supports picture?

The img is required, not vestigial. Browsers without picture support render it directly, so without it nothing shows for them. It also carries the alt text, the width and height attributes, and the src the browser falls back to when every source is skipped. Removing it breaks older browsers and loses your accessibility text.

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