noted.do
The Tech Guy

JPEG, PNG, WebP, AVIF - Which One When

Short version first, since that's what most people want: photos as AVIF or WebP with a JPEG fallback, screenshots and graphics with sharp edges as PNG or lossless WebP, logos and icons as SVG. That covers almost everything. If you want to know why, read on.

JPEG is the old workhorse for photos, and it's still everywhere because literally everything can open it. It uses lossy compression, meaning it throws away detail your eye is unlikely to miss, and the quality slider decides how much. For a photo of a mountain range, that's a great trade. For text or a screenshot, it's terrible, because those crisp edges turn into fuzzy, blotchy halos (the "JPEG artifacts" look). JPEG also has no transparency.

PNG is lossless. Every pixel comes out exactly as it went in. That makes it perfect for screenshots, diagrams, UI graphics, anything with flat colors and hard edges, and it supports transparency. The trade-off is size. Save a photo as PNG and you'll get a file many times bigger than the JPEG with no visible improvement. That's probably the most common image mistake on the web.

WebP came along to do both jobs. It has a lossy mode for photos and a lossless mode for graphics, it supports transparency, and it supports animation, all usually at smaller sizes than the JPEG or PNG equivalent. Every current major browser supports it, so for websites it's a safe default now.

AVIF is newer and generally compresses even better than WebP, especially for photos at lower file sizes, where it holds up noticeably better before things start looking smeared. The downsides: encoding is slower, some older software and devices can't open it, and image editors have been slower to support it. Browser support is good across the current major browsers, but it's the format where I'd most want a fallback.

Two others worth a mention. GIF is really only around for animation now, and it's bad at it: limited colors and huge files. A short muted video file or an animated WebP is almost always smaller and looks better. And SVG isn't pixels at all. It's a text file describing shapes, so it stays perfectly sharp at any size and is often tiny. For logos and icons, it's the obvious pick. (Just be careful accepting SVG uploads from users on your own site, since SVG files can contain scripts.)

On a website you don't have to pick just one. The <picture> element lets the browser choose the best format it supports:

<picture>
  <source srcset="photo.avif" type="image/avif">
  <source srcset="photo.webp" type="image/webp">
  <img src="photo.jpg" alt="A harbor at sunset" width="1200" height="800" loading="lazy">
</picture>

The browser goes down the list and uses the first one it understands, landing on the plain JPEG if all else fails. Keep the width and height on the <img> so the page doesn't jump around while it loads.

And honestly, the format matters less than the size. A 4000-pixel-wide AVIF is still a lot heavier than it needs to be if you're showing it at 800 pixels. Resize first, then pick the format. Tools like Squoosh are great for trying different formats and quality levels side by side so you can see the difference for yourself.

Comments

Be kind. See the rules.