WebP vs PNG vs JPEG vs AVIF
Compare JPEG, PNG, WebP and AVIF: how each compresses, where each fits, and how to serve modern formats with a safe fallback.
By the tools4free.dev team · Last reviewed 4 December 2026
Use JPEG or WebP for photographs, PNG or lossless WebP for sharp graphics that need exact pixels, and AVIF when you want the smallest files and can accept slower encoding. Modern browsers support WebP and AVIF, so the safest approach is to serve a modern format with a JPEG or PNG fallback. This guide explains how each format works, when to choose it, and how to serve more than one.
Lossy and lossless: the key idea
A lossless format stores every pixel exactly. Decode the file and you get the original image back, bit for bit. A lossy format throws away detail the eye is unlikely to notice, which makes files much smaller, but each save at a lower quality setting makes the loss permanent. Lossy suits photographs, where noise and gradients hide the changes. Lossless suits screenshots, logos and diagrams, where hard edges and flat colour would show artefacts as halos or blur.
It helps to know what the uncompressed size is. A 1200 x 800 pixel image with four bytes per pixel (red, green, blue and alpha) is 1200 x 800 x 4 = 3,840,000 bytes, about 3.7 MiB in memory. The file formats below exist to shrink that number for transfer, and the browser still has to decode it to that full size to draw it.
The four formats at a glance
| Feature | JPEG | PNG | WebP | AVIF |
|---|---|---|---|---|
| Compression | Lossy | Lossless | Lossy and lossless | Lossy and lossless |
| Transparency (alpha) | No | Yes | Yes | Yes |
| Animation | No | APNG extension | Yes | Yes |
| Best for | Photos, maximum compatibility | Logos, UI, screenshots | General web use | Photos where size matters most |
| Encoding speed | Very fast | Fast | Moderate | Slow |
| Browser support | Universal | Universal | Current major browsers | Current major browsers |
Support for WebP and AVIF is broad in current major browsers, but the details change over time and differ for older versions, so check the MDN image-format guide linked at the end before you drop a fallback.
JPEG: the universal photo format
JPEG has been the default for photographs for decades. It divides the picture into small blocks and discards fine detail. It has no transparency and it shows blocky artefacts at low quality, particularly around text and sharp edges. Its great strengths are that every device can open it and that every tool can create it. It remains a fine choice when you cannot control where the image will be opened, such as an email attachment or an upload to a third-party system.
PNG: exact pixels and transparency
PNG compresses without losing data and supports a full alpha channel, so it handles logos with soft shadows and interface screenshots well. It is poor for photographs: the files are large because noisy natural images do not compress well losslessly. PNG can also store a reduced palette of up to 256 colours, which makes flat graphics much smaller when you can accept the colour limit.
WebP: a flexible all-rounder
WebP can behave like JPEG (lossy, small photos) or like PNG (lossless, with alpha), and in lossy mode it can still carry transparency. That makes it a practical single format for most of a website. It is a good default when you want better compression than JPEG or PNG without the slower encoding that AVIF needs.
AVIF: the smallest files
AVIF is based on the AV1 video codec. It typically compresses photographs more efficiently than JPEG or WebP at similar visual quality, and it supports transparency, animation, and high bit depths and wide colour. The costs are slower encoding and, in some cases, less predictable results at very low quality settings, where smooth areas can look waxy. Because it is expensive to produce, it works best as part of a build step or conversion tool, not something you create by hand for every upload.
Worked example 1: choosing a format per asset
A small shop site has four kinds of image. A reasonable plan:
- Product photographs: AVIF first, WebP second, JPEG as the fallback.
- Logo with a transparent background: SVG if it is vector art; otherwise PNG or lossless WebP.
- Screenshots of the admin screen for documentation: PNG or lossless WebP, so that text stays crisp.
- Short product demo loops: a video file in an MP4 or WebM container is usually far smaller than a GIF; if you must use an image, animated WebP or AVIF is the better option.
Note that vector graphics belong to a different category. An icon or logo drawn as shapes is smaller and sharper as an SVG at any size than any raster format.
Worked example 2: serving formats with the picture element
The picture element lets the browser choose the first format it understands:
<picture>
<source type="image/avif" srcset="hero-800.avif 800w, hero-1600.avif 1600w">
<source type="image/webp" srcset="hero-800.webp 800w, hero-1600.webp 1600w">
<img src="hero-800.jpg"
srcset="hero-800.jpg 800w, hero-1600.jpg 1600w"
sizes="(min-width: 900px) 800px, 100vw"
width="800" height="500" alt="Describe the picture">
</picture>
The browser reads the sources from top to bottom, skips any type it cannot decode, and falls back to the img. The width and height attributes reserve space so that the layout does not jump when the image loads. The sizes attribute tells the browser how wide the image will be shown, so it can pick the right file from the srcset. Add loading="lazy" to images that start below the fold, but not to the main image visible at the top of the page.
Beyond the format: size and quality
Choosing a format matters less than shipping the right dimensions. A 4000-pixel-wide photo displayed in an 800-pixel slot wastes most of its bytes in any format. Resize first, then compress. For lossy formats, a quality setting between about 70 and 85 is a common starting range for photographs, but judge by eye on your own images, since results depend on the content. Strip metadata you do not need; camera files may carry location data you would prefer not to publish.
Common mistakes
- Saving photographs as PNG. The files can be many times larger than a good JPEG or WebP.
- Saving screenshots with text as lossy JPEG, which smears the letters.
- Re-saving a lossy file repeatedly. Keep the original and export from it each time.
- Converting a JPEG to PNG and expecting quality to improve. The lost detail does not come back; the file just gets bigger.
- Dropping the fallback and breaking older browsers, email clients or image previews that do not support the new format.
- Serving full-resolution images and relying on CSS to shrink them.
- Lazy-loading the top banner, which delays the largest paint.
- Forgetting alt text. The format does not matter to a screen reader, but the description does.
Checking the result
Compare the original and converted files at 100% zoom, looking at faces, text edges and smooth gradients such as skies. Compare the file sizes in bytes. If a lossless PNG is smaller than the lossy version of a flat graphic, believe the numbers, since that does happen. Finally, load the page with the browser's developer tools network panel open to confirm the format that was actually delivered.
Frequently asked questions
Is AVIF always smaller than WebP?
Often, for photographs, but not always. Results depend on the image and on the encoder settings. Test your own images rather than relying on a general rule.
Does the image format affect SEO?
Not directly. Smaller files load faster, which helps page experience, and well-described images with useful alt text help search engines understand them. The format itself is not a ranking label.
Should I replace GIFs?
For animation, usually yes. Video or animated WebP and AVIF are typically much smaller than GIF and are not limited to 256 colours.
What about HEIC from phones?
HEIC is common on phones but is poorly supported on the web. Convert it to JPEG, WebP or AVIF before publishing.