ImagesWebTools

Image compression without visible quality loss: WebP, JPEG and AVIF in practice

How large an image should be, when WebP beats JPEG, why AVIF does not always work on canvas, and how to check the result without a designer’s toolkit.

4 min read

Images are the heaviest part of a typical article. One 4K PNG screenshot can weigh more than all the HTML, CSS and JavaScript on the page, while being displayed in an 800 px column. Let us choose a format without ruining the picture.

Three numbers that define the weight

  1. Resolution. Pixels are data. Doubling the width quadruples the area.
  2. Format. WebP and AVIF compress more efficiently than JPEG and PNG.
  3. Quality. Dropping quality from 95 to 80 usually halves the file, and the difference is invisible.

A practical target: an in-article image should stay under 250 KB, a thumbnail under 80 KB. If it is larger, there is almost always something to compress.

WebP versus JPEG

Both are lossy and both use the discrete cosine transform, but WebP adds block prediction and performs better at low bitrates. On photos at comparable visual quality, WebP usually saves 20–35%.

When JPEG still makes sense:

  • the file goes to an old application or a mail client with limited support;
  • you need maximum compatibility with corporate software;
  • transparency is not required and the image will be re-saved repeatedly.

AVIF: better, with caveats

AVIF, based on AV1, produces even smaller files, especially on photos with smooth gradients. The problems:

  • Encoding is slower, particularly in the browser.
  • canvas.toBlob('image/avif') support is inconsistent. Chrome can encode AVIF through canvas; Firefox and Safari do not, or only partially. An online converter therefore cannot guarantee AVIF everywhere.
  • Decoding is wider than encoding: most browsers can display AVIF, far fewer can create it.

Our compression tool therefore offers WebP, JPEG and PNG: formats that encode predictably everywhere.

PNG: only when you need transparency

PNG is lossless. For an interface screenshot with text it gives sharp edges but is 5–15 times larger than WebP. If transparency is not needed, PNG almost always loses.

For images with transparency there is a compromise: WebP supports an alpha channel and compresses better than PNG. Keep PNG if the image must open in an old editor or be printed.

Which quality to choose

Image type Quality Comment
People and nature photos 75–82 Artefacts are barely visible, weight is minimal
Interface screenshots 82–88 Text edges must stay sharp
Text inside an image 88–92 Or PNG if the text is small
Previews and thumbnails 70–78 Viewed from a distance, detail does not matter
Illustrations with smooth gradients 80–85 Lower values introduce banding

A simple check: open the result at 100% and look at contrast transitions. If you see a halo around letters, raise the quality.

Reduce resolution, not just quality

If an image is displayed at 800 px, there is no reason to store 3000 px. Reducing width gives a bigger win than any compression setting.

Guidance for a content site:

  • full-width illustration — 1600–1920 px;
  • in-article image — 1200–1400 px;
  • card in a grid — 800 px;
  • mobile version — 640–800 px.

For Retina displays, prepare a 2x variant and serve it through srcset. But do not double everything: extra srcset sizes increase HTML weight and processing time.

How to serve images on a site

The minimum worth doing:

<img
  src="/images/browser-memory-800.webp"
  srcset="/images/browser-memory-800.webp 800w,
          /images/browser-memory-1600.webp 1600w"
  sizes="(max-width: 900px) 100vw, 800px"
  width="1600" height="900"
  loading="lazy" decoding="async"
  alt="Browser task manager showing tab processes"
/>

What matters here:

  • width and height set the aspect ratio and prevent layout shift (CLS);
  • loading="lazy" defers off-screen loading;
  • srcset gives mobile a smaller file;
  • alt describes the content, not “image”.

Do not lazy-load the first image on the page: it delays LCP. Use fetchpriority="high" for it.

Checklist before publishing

  • Width is no more than 2× the displayed size.
  • WebP, unless transparency or compatibility is required.
  • Quality checked by eye at 100%.
  • EXIF and GPS removed (converters usually do this automatically).
  • width/height are set.
  • File size is within 250 KB.
  • For transparent PNG — consider WebP instead.

Quick result check

  1. Compress the file in the tool to WebP at quality 80.
  2. Download it and open it next to the original in two tabs.
  3. Compare contrast edges: letters, icons, thin lines.
  4. If you cannot see a difference, keep it. If you can, raise quality by 5 points.

Image compression is the cheapest site-speed optimisation: it does not require code changes, and the effect is visible immediately in Lighthouse and on mobile networks.

Sources

Related reading

All articles →