SquishPixel Blog · Guides

JPEG, PNG, WebP or AVIF: how to choose an image format

The format is the decision that most affects an image's file size. The right answer depends on what is in the picture and where it will be used. This guide gives the short version first, then the reasoning.

The short version

ImageUseFallback
PhotoAVIF or WebPJPEG
Photo with a transparent backgroundWebP or AVIFPNG
Logo, icon or simple illustrationSVGPNG
Screenshot, diagram or pixel artLossless WebPPNG
Short animationVideo (MP4 or WebM)Animated WebP
Image for an email or a link previewJPEG or PNGNone needed

The formats

JPEG

Lossy, with no transparency. It has been the standard for photographs since the 1990s and opens in everything. A well-encoded JPEG is still a reasonable choice for photos, and it is the safe option when you do not control where an image ends up.

PNG

Lossless, with full transparency. It reproduces sharp edges and flat colour exactly, which makes it right for screenshots, diagrams and graphics with text. It is the wrong choice for photographs: a photo saved as PNG is typically several times larger than the same photo as JPEG.

WebP

Lossy or lossless, with transparency and animation in either mode. At the same visual quality it is usually smaller than JPEG for photos and smaller than PNG for graphics. Every current major browser supports it. For most sites it is the practical default.

AVIF

Lossy or lossless, with transparency and support for high dynamic range and wide colour. It is built on the AV1 video codec and usually produces the smallest files of the four for photographs, most noticeably at lower quality settings. It takes longer to encode. Current versions of Chrome, Edge, Firefox and Safari all display it.

SVG

Not a pixel format at all. An SVG describes shapes, so it stays sharp at any size and is often only a few kilobytes. Use it for logos, icons and simple illustrations. It cannot represent a photograph.

GIF

Limited to 256 colours and inefficient for animation. Anything a GIF does, a short muted video or an animated WebP does in a much smaller file.

Four questions that settle it

  1. Is it a photograph or a graphic? Photographs change colour gradually and suit lossy formats. Graphics have hard edges and flat areas and suit lossless ones.
  2. Does it need transparency? That rules out JPEG.
  3. Where will it be shown? On a web page you control, use a modern format. In an email, in a link preview, or anywhere someone will download and reuse it, stay with JPEG or PNG.
  4. How many images are there, and how often do they change? AVIF's slow encoding matters if you process thousands of images on every build. It does not matter for a handful of hero images.

Serving a modern format with a fallback

The picture element lets you offer several versions of one image. The browser takes the first it understands:

<picture>
  <source srcset="hero.avif" type="image/avif">
  <source srcset="hero.webp" type="image/webp">
  <img src="hero.jpg" alt="Workshop interior" width="1600" height="900">
</picture>

Because all current browsers support WebP, many sites now serve WebP alone and leave out the fallback. Whether you need one depends on how old your visitors' browsers are, which your analytics will tell you.

A note on JPEG XL

JPEG XL is a newer format with strong compression and the useful ability to repack an existing JPEG with no loss at all. Browser support is incomplete, so check the current position before you rely on it for web pages.

Convert and compare

The quickest way to choose is to try it on your own image. SquishPixel converts between JPEG, PNG, WebP and AVIF in your browser, shows the size of each result and lets you compare it with the original. Nothing is uploaded.