Dev.to WebDev 🛠 Dev 👁 0 📖 4 min read

The picture element: which format each browser downloads

A <picture> element makes each browser download exactly one file. In my test, Chromium 149, Firefox 151 and WebKit 26.5 all picked the AVIF: 34,898 bytes, against 79,671 for the JPEG fallback. That is 44,773 bytes fewer,

The picture element: which format each browser downloads

A <picture> element makes each browser download exactly one file. In my test, Chromium 149, Firefox 151 and WebKit 26.5 all picked the AVIF: 34,898 bytes, against 79,671 for the JPEG fallback. That is 44,773 bytes fewer, or 56.2%. The savings depend on two things people get wrong: source order and the type attribute.

What does the browser download from a picture element?

It walks the <source> children in order and takes the first one it can use. MDN's picture reference says a source with a type the browser does not support is skipped, and the <img> is the fallback when no source matches. The first match wins. The rest are never requested.

I made five files from one 4964 × 2782 camera photo, resized to 1280 px wide: mozjpeg q80, WebP q75 and AVIF q50 (effort 4). Then I served three pages from a local Node server that logs every response.

<picture>
  <source type="image/avif" srcset="p-1280.avif">
  <source type="image/webp" srcset="p-1280.webp">
  <img src="p-1280.jpg" width="1280" height="717" alt="">
</picture>

Bytes downloaded for JPEG only, WebP first and AVIF first

  • JPEG only: 79,671 bytes.
  • WebP source first: 46,384 bytes (41.8% fewer than JPEG).
  • AVIF source first: 34,898 bytes (56.2% fewer).

Chromium, Firefox and WebKit gave the same result on all three pages. The server log showed one image request each time.

Does source order change the bytes?

Yes, and nothing warns you. I swapped the two sources so WebP came first. Every browser took the WebP and never looked at the AVIF. That cost 11,486 extra bytes, 32.9% more than the AVIF. List the smallest format first.

What if the browser does not support a type?

All three engines I have installed support AVIF, so I could not watch a real fallback. I simulated one with a made-up type, image/x-blinkimg-test. This is the page:

<picture>
  <source type="image/x-blinkimg-test" srcset="p-1280.avif">
  <source type="image/x-blinkimg-test2" srcset="p-1280.webp">
  <img src="p-1280.jpg" width="1280" height="717" alt="">
</picture>

All three browsers skipped both sources and downloaded the JPEG: 79,671 bytes. No request went out for the skipped files. An old browser behaves the same way with image/avif.

Note: type is a promise about the file. If the browser supports the type and the file is missing, there is no fallback. I put type="image/jxl" first and pointed it at a file that does not exist. Chromium and Firefox skipped it and loaded the AVIF. WebKit 26.5 matched the type, requested the missing file and rendered nothing (naturalWidth was 0). The <img> never ran.

Do you need the type attribute?

Without type, the browser cannot skip a source by format. It only skips on media or when it fails to decode. In my run a type-less AVIF source worked, because all three engines decode AVIF. On an engine that cannot, you would get a broken image, not a JPEG. Always write the type.

How do you check what loaded?

Read currentSrc from the <img> in the console:

document.querySelector('picture img').currentSrc

For a page you do not own, the page image analyzer lists each image's format and weight.

Does the AVIF win hold at every width?

I made the three formats at five widths from the same photo. AVIF was smallest every time:

  • 320 px: AVIF 4,656, WebP 6,316, JPEG 9,589 bytes.
  • 640 px: AVIF 12,558, WebP 16,862, JPEG 27,154.
  • 960 px: AVIF 21,926, WebP 28,936, JPEG 50,630.
  • 1280 px: AVIF 34,898, WebP 46,384, JPEG 79,671.
  • 1920 px: AVIF 66,799, WebP 85,468, JPEG 153,394.

The gap grows with width. At 320 px the AVIF saves 4,933 bytes over the JPEG. At 1920 px it saves 86,595. These are my quality settings (q50 for AVIF is not equal to q80 for JPEG in every photo), so compare by eye before you ship.

Is the file size the only cost?

No. A smaller AVIF can still cost more to decode on a weak phone, and I did not time decoding. The byte count is what I measured. Treat it as the network half of the answer.

What should you do?

  1. Put AVIF first, WebP second, JPEG in the <img>.
  2. Write the right type on every source.
  3. Keep width and height on the <img>. The browser uses them for the layout box.
  4. Make sure every file in a <source> exists.

For making the three files, the image optimization guide covers when each format wins.

How I measured

  • Apple Silicon Mac, 2026-10-18. Node 24.22.0, sharp 0.35.4 (libvips 8.18.6), Playwright 1.61.1, Chromium 149.0.7827.55, Firefox 151.0, WebKit 26.5.
  • Source: image-compressor-sample-camera-photo.jpeg, 4964 × 2782, 9,804,300 bytes. Resized to 1280 px wide.
  • Bytes are response body sizes from a local server log (no headers, no compression). KB = 1,000 bytes.
  • Raw output: measured.json in this folder.

What I did not test

I did not test a browser without AVIF support, only a fake type. I did not test a CDN, HTTP caching or a slow network.

I build Blinkimg, an image compressor and converter with a developer API. I wrote this article with help from an AI assistant (Claude), which ran the code on my machine; every number in it comes from those runs.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.