Sub topic 9
AVIF: higher compression, with trade-offs
This chapter assumes you know the difference between lossy and lossless compression, and that you have exported JPEG and WebP files before. AVIF is the newest of the common web image formats. It usually produces the smallest files, but it has costs you should know before you switch to it.
What AVIF is
AVIF is an image format based on the AV1 video codec. It supports lossy and lossless compression, transparency, animation, and wide color ranges such as HDR. Its main appeal is size. At similar visual quality, an AVIF photo is often noticeably smaller than the same photo as a JPEG, and often smaller than WebP. The exact saving depends on the image, so measure it instead of trusting a headline figure.
Where AVIF does well
- Photographs and gradients. AVIF handles smooth color transitions with less banding than JPEG at low file sizes.
- Transparency in photos. A cut-out product photo can keep its alpha channel at a much smaller size than a PNG.
- Large hero images. The bigger the file, the more a percentage saving is worth.
Trade-offs
| Concern | What to expect |
|---|---|
| Encoding speed | Slow. Large images can take many seconds to encode, which matters in batch exports. |
| Browser support | Current versions of the major browsers support it. Older browsers and some email clients do not. |
| Tool support | Some design tools and image viewers cannot open or export AVIF. You may need a command-line tool. |
| Small or flat images | Gains shrink for icons, screenshots with flat color, and tiny images. SVG or PNG may be better. |
| Soft detail | At low quality, AVIF tends to smooth away fine texture instead of showing JPEG-style blocks. |
Because of the support gaps, do not ship AVIF alone. Offer it first and keep a fallback behind it.
Serving AVIF with a fallback
The picture element lets the browser pick the first format it supports. List AVIF first, then WebP, then a JPEG in the img element.
<picture>
<source type="image/avif" srcset="hero.avif">
<source type="image/webp" srcset="hero.webp">
<img src="hero.jpg" width="800" height="450" alt="Team working at a shared desk">
</picture>The JPEG in the img element is the fallback and also carries the dimensions and alt text. You export three files for one image, so the extra storage and naming effort is part of the cost.
How the choice flows
Setting quality
AVIF quality numbers do not match JPEG numbers. A value that looks fine in JPEG can look too soft or too heavy in AVIF. Export a few quality levels, compare them at 100% zoom, and keep the lowest one that still looks right. Check faces, text edges, and gradients first, since those show problems earliest.
Exercise
You have a 1600-pixel-wide product photo and a 24-pixel line icon. For which one is AVIF the better candidate, and what must you add when you use it?
Show answer
The photo is the better candidate, because AVIF saves the most on photographic detail and smooth gradients. Use the picture element with a WebP or JPEG fallback so browsers that cannot decode AVIF still show the image. The icon should be an SVG.