How to Compress Images for the Web Without Losing Quality
How much each JPEG quality step saves, measured on 24 standard test photos, how WebP and AVIF compare at equal quality, and why resizing first matters more than any setting.
Lossy vs Lossless
Lossy compression (JPEG, lossy WebP, AVIF) discards detail; lossless (PNG, lossless WebP) keeps every pixel. Photos almost always go lossy; screenshots, UI and anything with small text are usually smaller and sharper as lossless WebP.
What the Quality Setting Buys
We saved the 24 photos of the Kodak test suite (768×512, lossless originals) as JPEG at four quality settings and measured file size and similarity to the original (SSIM on luminance, 1.0 = identical; October 13, 2026):
| Setting | Median size | Median SSIM |
|---|---|---|
| Lossless PNG (original) | 606 KB | 1.0 |
| JPEG q95 | 155 KB | 0.987 |
| JPEG q85 | 82 KB | 0.965 |
| JPEG q75 | 60 KB | 0.948 |
| JPEG q60 | 45 KB | 0.929 |
Going from q95 to q85 halves the file; q85 to q75 saves another 27%. Below about q75 the savings shrink while quality keeps falling. Most sites settle between 75 and 85 and check the busiest image by eye, because SSIM does not capture every artifact. At equal SSIM, WebP files were a median 26-27% smaller than JPEG and AVIF 37-38% smaller.
Resize Before You Compress
Pixel count matters more than any quality setting. A 4000×3000 photo shown at 800×600 sends 25 times the pixels needed (96% are thrown away by the browser). Export at the largest size it is displayed, or at twice that for high-density screens, and let srcset and sizes pick the right file. Without attributes or CSS sizing, also give every image width and height so the browser reserves space before it loads.
In Practice
For one-off images, the Image Compressor resizes and re-encodes in your browser: JPEG stays JPEG, PNG and WebP become WebP with transparency kept, and if the new file is not smaller it gives you the original back (tested on five files when we rebuilt it). For a site, automate it in the build (Sharp, libvips or Squoosh CLI) or through an image CDN, and serve AVIF or WebP with a JPEG fallback.
Frequently Asked Questions
What is the best image quality setting for web?
Should I use WebP or JPEG?
How much can image compression reduce file size?
- [1]Kodak Lossless True Color Image Suite (test photos) ↗
- [2]MDN, Image file type and format guide (AVIF and WebP support), checked Oct 13, 2026 ↗
- [3]Can I use, AVIF image format (usage data 2026-10-13) ↗
- [4]Can I use, WebP image format (usage data 2026-10-13) ↗
- [5]Wang et al., Image quality assessment: from error visibility to structural similarity (SSIM), IEEE TIP 2004 ↗
- [6]MDN, Responsive images (srcset and sizes) ↗
- [7]web.dev, Replace animated GIFs with video ↗
