The short answer
| JPEG | PNG | WebP | AVIF | |
|---|---|---|---|---|
| Compression | Lossy | Lossless | Lossy or lossless | Lossy or lossless |
| Transparency | No | Yes | Yes | Yes |
| Animation | No | No (APNG is separate) | Yes | Yes |
| Best at | Photos, anywhere | Screenshots, diagrams, sharp edges | Photos and graphics on the web | Photos at the smallest size |
| Weak at | Text, flat colour, transparency | Photos (very large files) | Software outside the browser | Encoding speed, older software |
| Works in | Everything | Everything | All current browsers | All current browsers |
- A photo for a web page: WebP, or AVIF with a fallback.
- A screenshot, diagram or anything with text and hard edges: PNG, or lossless WebP.
- A logo or icon: SVG if you have the vector original, otherwise PNG.
- An image going into an email, a document or an upload form you do not control: JPEG or PNG.
Lossy and lossless, and why it decides most of this
A lossless format stores every pixel exactly. A lossy format throws away detail the eye is unlikely to miss, which is how a photo shrinks to a tenth of its size. The two suit different pictures.
Photos are full of gradual change and noise, which lossy compression hides well and lossless compression cannot shrink much. Screenshots and diagrams are the opposite: large areas of identical colour and sharp edges, which lossless compression stores very compactly and lossy compression smears - the grey fringes around text in a JPEG screenshot are those artefacts.
Lossy compression is also not repeatable for free. Every time a JPEG is opened, edited and saved again, it is compressed again and loses a little more. Keep an original, edit from that, and export the lossy copy last.
JPEG
JPEG dates from 1992 and is the one format every device, application and website accepts. It is lossy, has no transparency and stores 8 bits per channel. At a quality setting around 75 to 85 a photo usually looks unchanged at normal viewing size; below that, blocky 8-by-8 pixel squares and halos around edges start to show.
Use it when compatibility matters more than size: email attachments, documents, print services, older content management systems, and any upload form that lists the formats it takes. A progressive JPEG, which loads as a blurry whole image that sharpens, is usually slightly smaller than a baseline one for large images.
PNG
PNG is lossless and supports full transparency, with a separate alpha value for every pixel. It is the right format for screenshots, user-interface graphics, diagrams, pixel art and anything that will be edited again. It is the wrong format for photos: a photo saved as PNG is commonly five to ten times the size of a good JPEG with no visible gain.
Two things shrink a PNG without changing the format. Reducing it to a palette of 256 colours or fewer (PNG-8) cuts the size sharply for flat graphics, and an optimiser that re-runs the compression more thoroughly can take off more without touching a pixel.
WebP
WebP, released by Google in 2010, does both jobs in one format: a lossy mode for photos and a lossless mode for graphics, each with transparency, plus animation. Google's own comparisons put lossy WebP at 25 to 34 percent smaller than JPEG at equivalent quality, and lossless WebP at about 26 percent smaller than PNG.
Every current browser has displayed WebP since Safari added it in version 14, in 2020. The gaps are outside the browser: some email clients, older desktop software and a number of upload forms still refuse it. Its maximum size is 16,383 pixels on a side, which matters only for very large images.
For most websites today, WebP is the default worth choosing: one format, clearly smaller than JPEG and PNG, with nothing to fall back to.
AVIF
AVIF stores an image using the AV1 video codec. At the same visual quality it is typically smaller than WebP for photos, sometimes by a wide margin at low bitrates, and it holds up better in smooth gradients such as skies, where JPEG and WebP show banding. It also supports 10 and 12 bits per channel and wide colour gamuts, so it can carry HDR images.
The costs are speed and reach. Encoding is much slower than for the other three, which matters if images are converted on demand. Browser support is complete but more recent: Chrome since version 85, Firefox since 93, Safari since 16 and Edge since 121. Outside browsers, support is still patchier than for WebP.
AVIF pays off for large photo-heavy pages - hero images, galleries, product photos - where the bytes saved are worth a fallback. For small images the difference from WebP is rarely worth the extra step.
Serving a modern format with a fallback
The picture element lets the browser pick the first format it can display, so you can offer AVIF or WebP without breaking anything older:
<picture>
<source srcset="photo.avif" type="image/avif">
<source srcset="photo.webp" type="image/webp">
<img src="photo.jpg" alt="Harbour at dusk" width="1600" height="1067">
</picture>Keep the width and height attributes on the img: they let the browser reserve the space before the file arrives, which prevents the page jumping as images load. An image CDN can do the same negotiation on the server from the browser's Accept header, with a single URL.
Size matters more than format
Changing format saves tens of percent. Sending the right number of pixels saves far more. A 4000-pixel-wide phone photo shown in a 800-pixel column carries 25 times the pixels it needs, and no format makes up for that. Resize to the largest size the image is displayed at - doubled for high-density screens - before choosing a format or a quality.
- Resize first, then compress. The image compressor does both, and converts between JPEG, PNG, WebP and, where your browser can write it, AVIF.
- Crop to the shape the layout needs rather than letting CSS hide the rest; the image cropper cuts to exact pixel sizes.
- Do not upscale. Enlarging a small image adds bytes and no detail.
- Re-encoding removes most metadata as a side effect, but if a photo is going to be published, check it with the EXIF viewer: phone photos often carry GPS coordinates.
These tools use your browser's own image encoders, so the formats on offer and the exact file sizes depend on the browser you run them in, and nothing is uploaded.
What about GIF, SVG and ICO?
- SVG is not a pixel format at all. It describes shapes, so it stays sharp at any size and is usually tiny. Use it for logos, icons and simple illustrations whenever you have the vector original.
- GIF is limited to 256 colours and compresses poorly. For animation, a short muted video or an animated WebP is a fraction of the size.
- ICO is a container for several small images, still used for
favicon.ico. Modern browsers also take PNG and SVG icons; the favicon generator produces the whole set. - HEIC is what iPhones save by default. Most browsers cannot display it, so convert it before putting it on a web page.
