How to Compress Images for the Web Without Visible Quality Loss

6 min read · Published 1 November 2026 · Updated 2 November 2026

Images are usually the heaviest part of a web page. Large files slow loading, use visitors' mobile data and hurt the metrics that search engines measure. The good news is that most photos can be made several times smaller with no difference a viewer would notice. The trick is to resize first, pick the right format, and then choose a sensible quality level.

Why image size matters

The largest image on a page is often the largest element a visitor waits for, so it directly affects the Largest Contentful Paint (LCP) measurement used in Core Web Vitals. A smaller file also saves bandwidth for people on slow or metered connections and reduces your hosting costs.

Lossy and lossless compression

Lossless compression makes a file smaller without changing a single pixel, but the savings are modest. Lossy compression throws away detail that the eye is unlikely to notice, and can reduce a photo to a fraction of its original size. Each lossy save loses a little more, so keep the original file and compress from it, instead of re-compressing a file that is already compressed.

Choosing the right format

  • JPG is a lossy format designed for photographs. It has no transparency. It is a safe, universally supported choice.
  • PNG is lossless and supports transparency. It is ideal for logos, icons, screenshots and graphics with flat colours and sharp edges, but files of photographs are large.
  • WebP supports both lossy and lossless modes and transparency, and usually produces smaller files than JPG or PNG at similar visual quality. It is supported by all current major browsers, so it is a good default for web images.
  • AVIF can be smaller still, but encoding is slower and tool support is less universal. Consider it once you have the basics in place.

Resize before you compress

A photo straight from a phone camera can be 4,000 pixels wide, while it is displayed in a column 800 pixels wide. The browser downloads every unused pixel. A good rule is to export at the largest size at which the image is displayed, multiplied by two for high-density screens. Resizing from 4,000 to 1,600 pixels wide reduces the pixel count by more than 80% before any quality setting is applied.

Choosing a quality level

For JPG and lossy WebP, a quality setting between about 70 and 85 usually looks the same as the original at normal viewing size, while saving a large share of the file size. Going above 90 increases the size a lot for almost no visible gain. Going below 60 starts to show blocky artefacts around edges and in smooth gradients such as skies. Always look at the result at 100% zoom, on the areas with the most detail, before you accept it.

What not to do

  • Do not save screenshots with text, or logos, as lossy JPG. Fuzzy halos appear around the letters. Use PNG or lossless WebP instead.
  • Do not scale a small image up. It will be blurry and the file will not be smaller.
  • Do not convert a JPG to PNG expecting better quality. The detail already lost cannot be recovered, and the file will be larger.
  • Do not compress the same file repeatedly. Quality drops each time.

Metadata and privacy

Photos often contain EXIF metadata such as camera model, date and sometimes GPS coordinates. Re-encoding an image in the browser typically drops this data, which reduces the file size slightly and prevents you from publishing the location where a photo was taken by accident.

Compressing in your browser

A browser-based compressor decodes the image, redraws it at the chosen size and saves it again in the format and quality you select. Because everything happens on your device, the picture is never uploaded to a server, which is convenient for private photos and documents.

A simple workflow

  1. Keep the original file safe.
  2. Resize to the largest display size (times two for sharp screens).
  3. Choose WebP or JPG for photos and PNG or lossless WebP for graphics.
  4. Start at quality 75–80 and check the result at 100% zoom.
  5. Aim for a main image well under a few hundred kilobytes, and set width and height attributes in your HTML so the page does not jump while loading.

Serve different sizes with srcset

Even a well-compressed image is wasteful if a phone downloads the desktop version. The srcset and sizes attributes let the browser choose the best file for the screen:

HTML

<img
  src="photo-800.webp"
  srcset="photo-400.webp 400w, photo-800.webp 800w, photo-1600.webp 1600w"
  sizes="(max-width: 600px) 100vw, 800px"
  width="800" height="533"
  loading="lazy"
  alt="Describe what the picture shows">

How much can you save?

A 4000 × 3000 photo has 12 million pixels. Resized to 1600 × 1200 it has about 1.9 million, which is only 16% of the original before any quality setting is applied. Add WebP at quality 80 and a typical photograph commonly ends up at a few hundred kilobytes instead of several megabytes. Exact numbers depend on the picture: smooth areas such as skies compress far better than detailed textures such as leaves or fabric.

Frequently asked questions

Is WebP safe to use?
Yes. WebP is supported by all current major browsers. If you must support a very old browser, you can serve a JPG fallback with the picture element.
Does compression remove EXIF data?
Re-encoding an image in the browser normally drops metadata such as camera model and GPS location. If you need to keep it, use a tool that preserves metadata, and check the result.
Should I use AVIF instead of WebP?
AVIF can produce smaller files, but it is slower to encode and not supported by quite as many tools. WebP is a good all-round default, and AVIF is worth considering for sites where every kilobyte counts.
How small should a hero image be?
There is no fixed rule, but as a guide, aim for a main image of a few hundred kilobytes at most on a typical page, and measure the effect on loading time instead of guessing.

Sources and further reading

Try it yourself: Image Compressor runs in your browser, free and with no sign-up.

More guides