Reference guide · images · Published 2026-08-15 · 4 min read
WebP and AVIF: modern image formats
Compare WebP and AVIF with JPEG for size, quality and browser support, and convert a site's image set without double-encoding loss.
- ·Format comparison
- ·When to use which
- ·Conversion steps
Why this matters
JPEG is the safest photographic format ever shipped and still universal, but its compression reflects an older default. WebP, supported by every current browser, and AVIF, supported by all modern major browsers, both beat JPEG on page weight for a similar visual result. Because images are usually the largest single download on a marketing page, per the image optimisation guide, choosing the modern format is one of the highest yielding changes you can make to page performance and bandwidth.
Format comparison
Byte sizes quoted below are for a typical photographic JPEG saved at quality 80. WebP photos usually land 25 to 35 percent smaller; AVIF commonly lands another 10 to 30 percent under WebP, with better low-bitrate behaviour.
| Property | JPEG | WebP | AVIF |
|---|---|---|---|
| Typical photo file size | baseline | 25 to 35 percent smaller | often a further 10 to 30 percent below WebP |
| Compression quality | good, blocky artefacts at high compression | good at equal size, fewer visible artefacts | strong at very low bitrates |
| Transparency | no | yes | yes |
| Animation | no | yes | yes (still evolving) |
| Legacy browser support | universal | not before 2020 | no Safari before Safari 16, needs a fallback |
When to use which
- Use WebP as the default for photographic images. It is the most broadly compatible modern format and works in a single plain
<img>tag in every current browser, with no server negotiation. - Use AVIF when you can serve through
<picture>or content negotiation with a WebP fallback, and you want the smallest bytes for photos, product galleries, or data-heavy pages. - Use lossless WebP for screenshots, line art, and graphics with transparency. Lossless WebP is often meaningfully smaller than lossless PNG for the same capture.
- Keep JPEG only for the emergency fallback branch inside the
<picture>tree, or for legacy clients you must keep compatible.
When JPEG stays the better choice
If the site audience still runs browsers from before roughly 2020, or you cannot build a publishing pipeline that generates alternatives reliably, a well-compressed JPEG served at the right size with strong caching beats a WebP you deliver inconsistently. Format choice never outweighs the basics of resize, compress, cache, and srcset.
Conversion steps
- Confirm what to convert. Run the Lighthouse image audit and look for JPEG files larger than the render size.
- Choose a build-time converter such as sharp,
cwebp, oravifenc. - Regenerate all derivatives from the original masters, never from an already-compressed JPEG.
- For AVIF, switch markup to
<picture>so every browser receives a decodeable format. - Keep the conversion in the build so it runs on every deploy, not a one-off manual script.
<picture>
<source srcset="/assets/hero.avif" type="image/avif">
<source srcset="/assets/hero.webp" type="image/webp">
<img src="/assets/hero.jpg" alt="Description" width="1600" height="900">
</picture>
Avoid double-encoding
The most common error is converting an already-compressed JPEG to WebP. Each lossy stage adds new blocking artefacts and loses fine detail. To avoid double encoding:
- Keep a high-quality master (PNG, TIFF, or a low-compression JPEG) that only editors touch.
- Generate WebP and AVIF as build-task derivatives from that master, never from a web-ready file.
- Compare visually in a browser side by side, not by file size alone, to confirm the quality is indistinguishable.
Then serve the derivatives from cache with long-lived headers, covered in the static asset delivery guide. The source image optimisation guide walks the rest of the chain: render sizing, srcset, lazy loading, and delivery.
> A note on effort: do not convert purely decorative or tiny images. The return is concentrated in the largest photographic files, usually the hero and the first few product shots.