WebP vs AVIF vs JPEG vs PNG: Which Image Format to Use
Which image format should you use? JPEG, PNG, WebP and AVIF compared for photos, screenshots and logos, and how to serve modern formats safely.
Images are usually the heaviest thing on a web page. On many sites they make up more of the download than all the HTML, CSS and JavaScript put together, and the biggest one is often the page's Largest Contentful Paint (LCP), the moment Google uses to judge how fast your page feels.
The good news is that picking the right format, and the right size, is one of the cheapest performance wins there is. This guide compares the four formats you'll actually use (JPEG, PNG, WebP and AVIF), says which to pick for which job, and shows how to serve modern formats without breaking older browsers.
The short answer
| You're publishing | Use | Fallback |
|---|---|---|
| Photos | AVIF or WebP | JPEG |
| Screenshots, UI, text in images | WebP (lossless) or PNG | PNG |
| Logos and icons | SVG | PNG |
| Images with transparency | WebP or AVIF | PNG |
| Animations | A short video (MP4 or WebM), or animated WebP | GIF only if you must |
If you only remember one thing: resize first, then pick a format. A 4000-pixel photo shown in a 800-pixel column is wasting most of its bytes, whatever the format.
JPEG: the old reliable
JPEG has been around since 1992, and every browser, phone, email client and image editor understands it.
- Good at: photos and anything with smooth gradients and natural texture.
- Bad at: sharp edges and flat colour. Text and screenshots get fuzzy "ringing" artefacts around edges.
- No transparency. A transparent PNG saved as JPEG gets a solid background.
- Quality: 75–85 is the usual sweet spot. Below about 60, blocky artefacts start to show.
JPEG is still the right fallback for photos, and a sensible choice for files people will download and open elsewhere.
PNG: lossless and exact
PNG keeps every pixel exactly as it was. That makes it ideal when exactness matters:
- Good at: screenshots, diagrams, UI mock-ups, pixel art, and images with text.
- Supports full transparency, including soft edges and shadows.
- Bad at: photos. A photo saved as PNG is often several times bigger than the same photo as a good JPEG, with no visible benefit.
PNG has no quality slider: it's lossless, so the way to make one smaller is to reduce its dimensions or its number of colours.
WebP: the safe modern default
Google released WebP in 2010, and today every current browser supports it (Safari was the last, in 2020).
- Lossy and lossless modes, so it can replace both JPEG and PNG.
- Transparency and animation are supported in both modes.
- Smaller files: lossy WebP is often around a quarter to a third smaller than a JPEG of similar visual quality, and lossless WebP is usually smaller than PNG.
- Quick to encode and decode, so it's fine for images generated on the fly.
If you want one modern format with almost no caveats, WebP is it.
AVIF: the smallest files
AVIF is based on the AV1 video codec, and it's newer: Chrome added it in version 85 (2020), Firefox in 93 (2021) and Safari in 16 (2022).
- The best compression of the four. For photos, AVIF is often around half the size of a JPEG that looks the same, and noticeably smaller than WebP, especially at low bitrates.
- Supports transparency, HDR and wide colour.
- Slower to encode, sometimes by a lot. That matters for build pipelines and on-the-fly resizing, not for the people viewing the page.
- Can over-smooth fine detail at aggressive settings. Skin, foliage and fabric texture may look a little "painted". Check your results rather than trusting a number.
AVIF quality numbers don't mean the same as JPEG's: an AVIF at quality 50–60 can look like a JPEG at 80. Always compare by eye.
What about GIF, SVG and JPEG XL?
- GIF is limited to 256 colours per frame and compresses poorly. An animated GIF is often many times bigger than the same clip as an MP4 or WebM video. Use
<video autoplay muted loop playsinline>instead. - SVG isn't a photo format at all: it's vector drawing instructions. For logos, icons and simple illustrations, it's tiny and sharp at every size. Just remember SVG can contain scripts, so never serve SVGs uploaded by users without sanitising them.
- JPEG XL has excellent compression and can repackage existing JPEGs losslessly, but browser support is still patchy. Check current support before relying on it.
Try it on your own images
Numbers from someone else's test photos only go so far. Your images, at your sizes, are what count. The image compressor in the toolkit lets you:
- Drop in, choose or paste an image.
- Switch between WebP, AVIF (if your browser can write it), JPEG and PNG.
- Move the quality slider and set a maximum size.
- Drag the before/after divider to compare at full resolution, and see the byte savings.
It runs entirely in your browser: nothing is uploaded. As a side effect, re-encoding also strips hidden metadata such as the camera model and the GPS location where a phone photo was taken, which is worth doing before you post a photo publicly anyway.
Resize before you compress
Format choice matters less than serving the right number of pixels. A rough rule: make an image about twice the width it's displayed at (for high-density screens), and no bigger.
| Displayed at | Export at most |
|---|---|
| A blog column, about 700 px wide | 1400 px |
| A full-width hero on desktop | 2560 px |
| A thumbnail, 300 px | 600 px |
For responsive layouts, let the browser pick from a few sizes with srcset and sizes:
<img
src="/images/harbour-1280.jpg"
srcset="/images/harbour-640.jpg 640w, /images/harbour-1280.jpg 1280w, /images/harbour-2560.jpg 2560w"
sizes="(min-width: 760px) 700px, 100vw"
width="1280"
height="853"
alt="Fishing boats in the harbour at sunrise"
loading="lazy"
decoding="async"
/>
sizes tells the browser how wide the image will be shown, so it can download the smallest file that's still sharp.
Serve modern formats with a fallback
The <picture> element lets each browser pick the first format it supports:
<picture>
<source type="image/avif" srcset="/images/harbour.avif" />
<source type="image/webp" srcset="/images/harbour.webp" />
<img src="/images/harbour.jpg" width="1280" height="853" alt="Fishing boats in the harbour at sunrise" />
</picture>
Browsers read the <source> elements top to bottom and download only one file. The <img> is both the fallback and the element that carries alt, width, height and loading.
If you use Next.js
The next/image component resizes and converts images for you, and serves WebP by default. To also offer AVIF, opt in:
// next.config.js
module.exports = {
images: {
formats: ['image/avif', 'image/webp'],
},
};
Most image CDNs (Cloudflare, Cloudinary, imgix and others) can do the same negotiation automatically, using the browser's Accept header.
Six habits that make images fast
- Always set
widthandheight(or a CSSaspect-ratio). The browser can reserve space before the image arrives, so the layout doesn't jump. That improves Cumulative Layout Shift (CLS). - Lazy-load images below the fold with
loading="lazy". - Don't lazy-load the LCP image. The hero image should load immediately. Add
fetchpriority="high"to it. - Resize to the displayed size, about 2× for sharp screens.
- Compare by eye at 100%, not just by file size. Look at faces, text and fine textures.
- Strip metadata you don't need. It's usually small, but it can include the location a photo was taken.
Summary
- Photos: AVIF or WebP, with JPEG as the fallback.
- Screenshots, text and UI: lossless WebP or PNG.
- Logos and icons: SVG.
- Animations: video, not GIF.
- Before any of that: resize to the size you actually display.
Try the formats side by side on your own photos with the image compressor, and you'll see in a few seconds which one wins for your images.