Why image size matters

Images are often the heaviest files on a page, so they are usually the quickest place to make a site faster. A smaller image loads sooner, uses less of a visitor’s mobile data and helps the main content appear sooner. That is the measure Google calls Largest Contentful Paint, which I explain in what a perfect page speed score taught me about building a simple website.

A real example from this site: the photo of me on the home page started life as a file of about 4.1 MB. The version a visitor downloads is a 12 KB WebP, which is more than 99 percent smaller, and it looks the same at the size it is shown. Nothing special was needed. It took the three steps below, in this order.

The three things that decide file size

  1. Dimensions. A photo that is 4,000 pixels wide, shown in a space 600 pixels wide, wastes most of its data.
  2. Format. The same picture can be a very different size as a JPEG, a PNG, a WebP or an AVIF.
  3. Compression level. How much detail you allow the file to lose, which is usually invisible at sensible settings.

Do them in that order. Resizing first gives the biggest saving and makes everything after it faster.

Resize to the size you need

Work out the widest the image will ever be displayed, then make the file about twice that width so it stays sharp on high-resolution screens. A picture shown at 600 pixels across does not need to be more than about 1,200 pixels wide. Any photo editor, or the free tools below, can resize.

Choose the right format

Format Best for Notes
JPEG Photos, where wide compatibility matters Works everywhere, but larger than the newer formats
PNG Screenshots, logos and anything with sharp text or transparency Lossless, so files can be large
WebP Almost everything Supported by around 97 percent of global browser traffic in 2026
AVIF Photos where every kilobyte counts Often smaller than WebP, supported by roughly 93 to 94 percent of browsers, and slower to create
SVG Logos and simple icons A drawing instruction rather than pixels, so it stays sharp at any size

Savings vary with the picture. AVIF tends to give the biggest saving on photographs and less on screenshots with text. Lighthouse, the test behind PageSpeed Insights, will flag images in older formats and estimate what newer ones would save.

If you want the safest approach, serve WebP and keep a JPEG or PNG fallback for older software. Most website platforms and plugins do that for you.

Compress, then look at the result

There are two kinds of compression.

  • Lossy throws away detail the eye is unlikely to notice. It gives much smaller files and suits photographs.
  • Lossless shrinks the file without changing a single pixel. The saving is smaller, but it is the safer choice for screenshots, charts and anything with text, where lossy artefacts can look messy around the letters.

Most tools offer a quality slider. Start high, around 80 percent, then compare the result with the original at the size it will be shown. If you cannot see a difference, you are done. If you can, nudge the quality up.

Tools for different situations

There is no single best tool. The right one depends on how many images you have and where they live.

Situation Option What to know
A few images, one-off Squoosh Free, runs in the browser and lets you compare before and after side by side
A few images, on your computer ImageOptim (Mac) or any photo editor’s export setting Nothing is uploaded anywhere
A website you build yourself Your framework’s own image tools This site uses Astro’s built-in processing, which resizes and converts to WebP when the site is built, at no extra cost
A WordPress site or a large existing library A plugin or service such as ShortPixel Handles hundreds of images in bulk and can keep doing it for new uploads

Where ShortPixel fits

I have used ShortPixel since it launched. I find it easy to use and affordable, and it suits a particular job: a site, WordPress for example, with a large library of images already uploaded, where fixing them one at a time would take forever.

  • It offers lossy, glossy and lossless modes, and you can try each on an image to compare.
  • It can create WebP and AVIF versions and optimise your existing images in bulk.
  • It has a free plan of 100 images a month, and paid plans for more. Prices change, so check the current pricing page.

It is not the answer for everyone. If you have a handful of images, Squoosh is free and quick. If your site builder already processes images, you may not need anything extra.

Two things people forget

  • Metadata. Photos often carry hidden details, such as the camera, the date and sometimes the location. Many tools can strip it. The photo on this site’s home page has had that data removed.
  • Alt text and file names. Compression does nothing for accessibility. Write short alt text that says what the image shows, and use a descriptive file name such as lecture-theatre-poll-results.webp instead of IMG_4821.webp.

A quick routine

  1. Resize to about twice the display width.
  2. Pick WebP, or JPEG for photos if you need the widest compatibility.
  3. Compress at around 80 percent quality and compare it with the original.
  4. Remove location and camera data from personal photos.
  5. Name the file clearly and add alt text.
  6. Re-test the page on PageSpeed Insights and compare the numbers.

If you are looking for photos to compress, my article on free stock photos you can use commercially covers where to find them and which licence rules to check. For the wider picture on making a site pleasant to use, see tips to improve your website’s user experience.

Sources

This guide is shared under CC BY 4.0 . You're welcome to reuse it in your own teaching with credit to Surabil.
Suggested credit: Surabil, “How to shrink images for the web without losing quality”, https://surabil.com/guides/compress-images-for-the-web/, licensed under CC BY 4.0.