Modern Image Formats — Performance

For a 1200 × 900 photo: JPEG about 180 KB, WebP about 120 KB (usually 25 to 35% smaller), AVIF about 80 KB (about half, and it can be 2 to 3 times smaller)…

These two files hold the same photo, 1200 × 900, and on screen you can barely tell them apart. One is about 180 KB, the other about 80 KB. The only difference is the format: JPEG and AVIF.

An image format is the way a file stores its pixels. It's like packing clothes in a suitcase: folded normally (JPEG), rolled tight (WebP), or in a vacuum bag (AVIF). Same clothes, usually less and less space. But an old wardrobe (an old browser) can only handle normal folding, so you still pack a normal version as a backup.

Four terms first

Format Compression Transparent Good for Browser support
JPEG lossy no photos all
PNG lossless yes logos, icons, screenshots, text all
WebP lossy and lossless yes photos and graphics all modern browsers
AVIF lossy and lossless yes photos modern browsers, Safari since version 16
SVG vector yes logos, icons, simple illustrations all

How much it saves

The 1200 × 900 photo from the Lab, at the same visible quality:

Format Size Compared to JPEG
JPEG about 180 KB the baseline
WebP about 120 KB a third smaller
AVIF about 80 KB more than half smaller
PNG about 1.4 MB almost 8 times bigger

The general rule: WebP is about 25 to 35% smaller than JPEG at the same quality. AVIF is about half, and for many photos it can be 2 to 3 times smaller (saving up to about 70%). So a 1920 × 1080 photo that's 150 KB as a JPEG becomes roughly 100 KB as WebP, and can drop to about 45 KB as AVIF. PNG is the wrong pick for a photo: lossless means every tiny detail is kept, so the file balloons.

The fallback order with <picture>

You already know <picture> from the Responsive Images lesson. The browser reads the <source> elements from the top, skips any whose type it doesn't know, and uses the first one it supports:

<picture>
  <!-- leanest first -->
  <source srcset="photo.avif" type="image/avif">
  <source srcset="photo.webp" type="image/webp">
  <!-- the fallback for every browser, plus alt and size -->
  <img src="photo.jpg" width="1200" height="900" alt="Rice fields in the morning">
</picture>
Browser AVIF? WebP? What it downloads
Latest Chrome yes yes photo.avif, about 80 KB
Safari 15 no yes photo.webp, about 120 KB
A very old browser (IE 11) no no photo.jpg, about 180 KB

Pick the format for the content

So for a transparent logo with sharp text: SVG if the logo is a vector, PNG if you only have it as an image. JPEG can't do it.

To convert, use squoosh.app in the browser for a file or two, or sharp in Node.js for many files at once during the build.

⚠️ Broken images, bloated files, or an AVIF nobody uses

TL;DR: For a 1200 × 900 photo: JPEG about 180 KB, WebP about 120 KB (usually 25 to 35% smaller), AVIF about 80 KB (about half, and it can be 2 to 3 times smaller). Serve them with <picture>: an AVIF <source> with type="image/avif", then a WebP <source> with type="image/webp", then a JPEG <img> as the fallback; each browser downloads the first file it supports, and only that one. Use SVG for logos and icons, PNG (or lossless WebP) for images with text or transparency, video for animations, and never save a photo as PNG.

⚡ Same photo, different file

Guess first: at the same visible quality, how much smaller is a WebP usually than a JPEG?

About 25 to 35%. AVIF is about half, and can be 2 to 3 times smaller. The 1200 × 900 photo in the Lab: JPEG about 180 KB, WebP 120 KB, AVIF 80 KB.

Meaning: A format is the way a file stores its pixels. Lossy throws away detail you can barely see, lossless keeps every pixel exactly the same.

⚡ Leanest on top

Write:

<picture>
  <source srcset="photo.avif" type="image/avif">
  <source srcset="photo.webp" type="image/webp">
  <img src="photo.jpg" width="1200" height="900" alt="Rice fields in the morning">
</picture>

Meaning: The browser reads the <source> elements from the top, skips any whose type it doesn't know, and downloads only the first file it supports. Without type, an old browser still takes the AVIF and the image breaks.

⚡ A format for the content

Meaning: Photos get AVIF, then WebP, with JPEG as the fallback. Logos and icons get SVG. Images with text or transparency get PNG (or lossless WebP). Animations get video, not GIF. Never save a photo as PNG.

What you will learn