AVIF vs WebP: which image format should you use?

Both make images far smaller than JPEG and PNG. How they differ in size, quality, features, speed and browser support, and how to serve both safely.

The SpeedPack team5 min read

ImagesPerformance
On this page
  1. The two formats in one minute
  2. File size
  3. Image quality and features
  4. Encoding and decoding speed
  5. Browser support
  6. How to serve both safely
  7. Which should you choose?
  8. How SpeedPack does it

Images are usually the heaviest part of a web page, and switching to a modern format is one of the easiest ways to make them lighter. The two modern formats that matter today are WebP and AVIF. Both beat JPEG and PNG on file size in most cases. So which one should you use?

Short answer: serve AVIF where the browser supports it, WebP as the fallback, and keep the original JPEG or PNG for anything else. The rest of this article explains why, and when the answer changes.

The two formats in one minute

WebP was created by Google and released in 2010. It is based on the VP8 video codec and supports lossy and lossless compression, transparency (alpha) and animation. After years of uneven support, it now works in every major browser.

AVIF is newer. It is based on the AV1 video codec from the Alliance for Open Media, a group that includes major browser and technology companies, and was finalized in 2019. It also supports lossy and lossless compression, transparency and animation, and adds features WebP does not have, such as higher bit depth and HDR.

Both are royalty-free.

File size

For photos, AVIF is usually smaller than WebP at the same visual quality, and WebP is usually smaller than JPEG. The gap is often biggest at the lower quality settings typically used on the web, where AVIF tends to keep a cleaner, smoother look while WebP and JPEG start to show blocky or blurry artifacts.

But "usually" is doing real work in that sentence. Results depend on the image, the encoder and the settings. Some images, especially simple graphics or images that are already heavily compressed, gain little or nothing from AVIF, and occasionally the AVIF file comes out larger. The only reliable answer for your images is to test a sample of them.

Image quality and features

A few differences matter in practice:

WebPAVIF
Lossy and losslessYesYes
TransparencyYesYes
AnimationYesYes
Bit depth8-bit8, 10 and 12-bit
HDR and wide colourNoYes
Full colour detail (4:4:4) in lossy modeNo, always 4:2:0Yes, optional

The last row deserves a word. Lossy WebP always stores colour at reduced resolution (called 4:2:0 chroma subsampling). For photos you will not notice. For images with sharp, saturated edges, such as red text on a white background, screenshots or logos, it can make edges look slightly soft or smeared. AVIF can keep full colour resolution when needed.

For those kinds of images, also consider lossless WebP, PNG, or SVG for logos and icons. The best format for a logo is usually not a photo format at all.

Encoding and decoding speed

Here WebP has the edge:

  • Encoding AVIF is slower and uses more CPU than encoding WebP, often by a wide margin, especially at the higher-effort settings that give the smallest files. If you convert images on your own server every time someone uploads, this matters. If the conversion happens once, in advance or in the cloud, it matters much less.
  • Decoding (the work the visitor's device does to display the image) can also be somewhat heavier for AVIF. For typical web images on modern devices this is rarely a problem, but it is one reason not to use enormous AVIF images where a smaller one would do.

A progressive JPEG shows a blurry version first and sharpens as data arrives. WebP has no progressive mode, and while AVIF can be stored in layers, that is rarely used and browser support for it varies. In practice, a large WebP or AVIF image appears once enough of it has loaded. Keeping file sizes small and preloading your main image is the way to deal with that.

Browser support

Every current major browser supports WebP, and every current major browser supports AVIF too, though AVIF support arrived later, and some browsers took several years to add it. Visitors on old browsers or old operating system versions may still lack one or both.

Check Can I use (caniuse.com) for the exact versions if you need to support older devices. In practice, the safe approach is the same either way: always provide a fallback.

How to serve both safely

There are two common ways to give each visitor the best format their browser supports.

Option 1: the picture element

<picture>
  <source srcset="photo.avif" type="image/avif">
  <source srcset="photo.webp" type="image/webp">
  <img src="photo.jpg" alt="A description of the photo" width="1200" height="800">
</picture>

The browser picks the first format it supports and ignores the rest. Keep the width, height and alt on the <img>; they still apply. This works anywhere, but it means changing the HTML for every image.

Option 2: content negotiation

Browsers send an Accept header listing the image formats they support. A server or CDN can read it and send AVIF, WebP or the original from the same URL. Your HTML does not change at all.

If you do this, the response must include Vary: Accept (or the CDN must otherwise key its cache on the format), so that a cache does not store the AVIF version and hand it to a browser that cannot show it.

Which should you choose?

  • Photos and large hero images: AVIF first, WebP as fallback. This is where AVIF's savings are largest.
  • You convert images on your own server, on upload, with limited CPU: WebP is the pragmatic choice. It is fast to encode and still much smaller than JPEG.
  • Screenshots, UI images, text in images: test lossless WebP and AVIF against PNG and keep the smallest that looks right.
  • Logos and icons: SVG where possible.
  • Animated GIFs: convert them. Animated WebP, animated AVIF, or a short video file are all far smaller than GIF.

Whatever you choose, the format is only one part of the job. Serving images at the right size for the screen (with srcset and sizes), compressing sensibly, and not lazy-loading the main image above the fold often matter just as much. Our guide to Largest Contentful Paint covers those steps.

How SpeedPack does it

SpeedPack converts your images in our cloud, so your server does none of the encoding work. Every plan gets WebP versions. On the Pro plan, AVIF versions are added too (in Strong and Ludicrous modes, or by turning AVIF on in custom settings). Visitors get the best format their browser accepts from the same image address, with the right caching headers, and the original stays as the fallback. Animated GIFs are turned into animated WebP, and images can be resized to the width they are really shown at.