How to Optimize Images for Web Without Losing Quality (2026)
Resize first, then compress: one camera photo went from 2,466 KB to 281 KB by resizing alone. We measured JPEG quality settings, WebP and AVIF at equal SSIM on eight test photos, and what still matters when the browser loads the file.
Where the Bytes Go
Images are still the heaviest part of most pages. HTTP Archive's 2024 Web Almanac measured median image bytes of 1,054 KB on desktop homepages and 900 KB on mobile ones, and 442 KB and 348 KB on inner pages. Dornauer and Felderer (2023, found through alphaXiv) put images at about 41% of the median page's request size in July 2023 (1,010.6 KB of 2,449.4 KB). Their crawl of 58,057 popular sites also showed how slowly formats change: of 2.66 million images, 33.2% were JPEG, 32.4% PNG, 19.9% SVG, 11.3% GIF and 3.0% WebP, with AVIF and every other format together under 0.1%.
So the easy wins are still on the table for most sites. We measured where they come from, in order of size.
Resize First, Then Compress
A phone photo or camera file is usually several times wider than any slot on a page. We took one 5,363 × 3,576 photo from Wikimedia Commons (Vihorlat (v zime) 046, CC BY-SA 4.0) and saved it at four widths and two quality settings with Pillow 12.1:
| Width | JPEG q85 | JPEG q60 | WebP q85 | WebP q60 |
|---|---|---|---|---|
| 5,363 px (original size) | 2,466 KB | 1,319 KB | 1,490 KB | 709 KB |
| 3,200 px | 1,018 KB | 541 KB | 741 KB | 358 KB |
| 1,600 px | 281 KB | 149 KB | 220 KB | 108 KB |
| 800 px | 76 KB | 42 KB | 61 KB | 30 KB |
Dropping the quality from 85 to 60 at full size saved 47%. Resizing to 1,600 px at quality 85 saved 89%, and the result still looks sharp on a 1,600 px slot. Resize to the largest size the layout will actually show, then use srcset and sizes so phones fetch a smaller file than desktops. The Bulk Image Resizer resamples with a Lanczos-3 filter and never enlarges a smaller image.
Quality Settings, Measured
Quality numbers are encoder settings, not a percentage of anything. To see what they buy, we encoded eight photos from the Kodak Lossless True Color Image Suite (768 × 512 each) and scored every result against the original with SSIM, a structural-similarity measure where 1.0 means identical. Medians across the eight:
| JPEG quality | Median size | Median SSIM |
|---|---|---|
| 60 | 39.7 KB | 0.939 |
| 70 | 47.3 KB | 0.950 |
| 75 | 52.1 KB | 0.957 |
| 80 | 59.9 KB | 0.964 |
| 85 | 71.0 KB | 0.970 |
| 90 | 90.5 KB | 0.979 |
| 95 | 133.0 KB | 0.989 |
The curve bends sharply at the top. Going from quality 85 to 95 added 87% to the file for 0.019 more SSIM; going from 75 to 85 added 36% for 0.013. That is why 75 to 85 is the usual range for photos. Below that, check the result on the image itself: smooth gradients such as skies band first, and text in a photo blurs before faces do. SSIM is a rough guide rather than a verdict; a 2025 evaluation of quality metrics for high-fidelity compression from the University of Lisbon, the University of Konstanz and Cloudinary (also on alphaXiv) is about exactly that gap.
The numbers also do not carry across formats. AVIF at quality 60 scored 0.970, the same as JPEG at 85, so copying one quality value into a different encoder gives a different result.
WebP and AVIF at the Same Quality
For each of the eight photos we found the WebP and AVIF file that matched the JPEG quality 85 SSIM and compared sizes:
| Format | Median saving vs JPEG q85 | Range across 8 photos | vs JPEG q75 |
|---|---|---|---|
| WebP (libwebp 1.6.0) | 31% | 13% to 36% | 30% |
| AVIF (libavif 1.3.0) | 42% | 34% to 51% | 44% |
| PNG (lossless) | 8 times larger |
Google's own figure for WebP is 25% to 34% smaller than JPEG at equal SSIM, which matches what we saw. In browsers, Dornauer and Felderer re-encoded a test page's images to the same SSIM (0.95) and measured page load time across Chrome, Edge, Safari, Opera and Firefox: WebP loaded 1.21 times faster than JPEG and AVIF 1.15 times faster, while first contentful paint did not change significantly. MDN's image format guide lists AVIF in Chrome 85, Firefox 93, Safari 16.1 and Edge 121, so both formats are safe to serve with a fallback.
<picture>
<source type="image/avif" srcset="hero-1600.avif 1600w, hero-800.avif 800w" sizes="100vw">
<source type="image/webp" srcset="hero-1600.webp 1600w, hero-800.webp 800w" sizes="100vw">
<img src="hero-1600.jpg" width="1600" height="900" alt="Ridge above the clouds at dawn"
fetchpriority="high">
</picture>
PNG is the right choice for screenshots, logos and anything with sharp edges or transparency, not for photos: on our eight photos the lossless PNG was a median 8 times the size of the JPEG at quality 85.
Loading the Image You Kept
The width and height attributes let the browser reserve the space before the file arrives; in our aspect-ratio tests that meant 225 px held in place instead of a 0 px box that jumps. Add loading="lazy" to images below the first screen, and never to the hero, which is usually the Largest Contentful Paint element. For the hero, fetchpriority="high" asks the browser to fetch it before other images; MDN's compatibility data lists it in Chrome and Edge 101, Safari 17.2 and Firefox 132.
Doing It in the Browser
Our Image Compressor works on your device, without uploading anything. Its Auto mode keeps a JPEG as JPEG and turns PNG, WebP and GIF files into WebP, which keeps transparency. If a re-encode at the same size would not be smaller, it hands back the original with a note rather than a bigger file. The Image Converter changes formats and checks each output file's signature before offering it. For format choices beyond photos, see our guide to choosing an image format.
Frequently Asked Questions
Is WebP better than JPEG?
Does this tool upload my images?
What about AVIF?
- [1]HTTP Archive, Web Almanac 2024: Page Weight (image bytes by page type) ↗
- [2]Dornauer B, Felderer M (2023), Web Image Formats: Assessment of Their Real-World-Usage and Performance across Popular Web Browsers, arXiv:2310.00788 (via alphaXiv) ↗
- [3]Evaluation of Objective Image Quality Metrics for High-Fidelity Image Compression (2025), arXiv:2509.13150 (via alphaXiv) ↗
- [4]Wang Z, Bovik AC, Sheikh HR, Simoncelli EP (2004), Image quality assessment: from error visibility to structural similarity, IEEE Transactions on Image Processing 13(4) ↗
- [5]Google for Developers, WebP compression study and FAQ ↗
- [6]MDN, Image file type and format guide (browser support), checked Oct 14, 2026 ↗
- [7]MDN browser-compat-data, img fetchpriority, checked Oct 14, 2026 ↗
- [8]Kodak Lossless True Color Image Suite (test images) ↗
- [9]Wikimedia Commons, Vihorlat (v zime) 046.jpg, CC BY-SA 4.0 (resize test photo) ↗