If you’ve ever watched a beautifully designed page crawl to load because of bloated images, you already know the stakes. Images typically account for more than 50% of a page’s weight, which means optimizing them is one of the highest-leverage things you can do for performance, SEO and conversion rates.
This guide goes beyond the usual “compress your images” advice. We’ll compare WebP, AVIF and JPEG with real file size data, walk through hands-on compression workflows using Squoosh and Sharp, and help you pick the right approach for your stack.
Why Image Optimization Still Matters in 2026
Even with faster networks and better devices, Core Web Vitals (especially Largest Contentful Paint) are still heavily influenced by image delivery. A poorly optimized hero image can single-handedly tank your LCP score and push you down the search rankings.
Good image optimization comes down to three pillars:
- Choosing the right format (JPEG, WebP, AVIF, PNG, SVG)
- Resizing to the actual dimensions needed
- Compressing with the right quality settings

WebP vs AVIF vs JPEG: The Real Comparison
Let’s cut through the marketing claims. Here’s how the three main formats actually behave when compressing the same 2400x1600px photograph (original PNG: 4.8 MB).
| Format | Quality Setting | File Size | Visual Quality | Browser Support |
|---|---|---|---|---|
| JPEG (MozJPEG) | 75 | 412 KB | Good | 100% |
| WebP | 75 | 258 KB | Very Good | ~97% |
| AVIF | 60 | 147 KB | Excellent | ~94% |
Key takeaways:
- AVIF wins on file size, often 50% smaller than JPEG at equivalent quality. It’s ideal for hero images and large photographs.
- WebP is the sweet spot for most projects: significantly smaller than JPEG with near-universal browser support.
- JPEG still has a role as a fallback and for legacy browser support.
When to Use Each Format
| Use Case | Recommended Format |
|---|---|
| Hero photos, large banners | AVIF with WebP fallback |
| Product galleries, thumbnails | WebP |
| Logos, icons, line art | SVG |
| Images with transparency | WebP or PNG |
| Animations | WebP (replaces GIF) |

Workflow 1: Manual Optimization with Squoosh
Squoosh (squoosh.app) is a free in-browser tool by Google that’s perfect for one-off optimizations or quick comparisons. Nothing is uploaded to a server, everything runs locally.
Step-by-Step Squoosh Workflow
- Open squoosh.app and drag your image into the browser.
- On the right panel, select the output format (try AVIF first).
- Adjust the quality slider. Start at 60 for AVIF, 75 for WebP, or 75 for MozJPEG.
- Use the side-by-side slider to compare original vs compressed.
- If needed, use the Resize option in the left panel to match the display dimensions on your site.
- Download and ship.
Pro tip: If you see banding in skies or artifacts on faces, bump quality up by 5 to 10 points rather than switching formats.
Workflow 2: Automated Optimization with Sharp (Node.js)
For any production site, manual optimization doesn’t scale. Sharp is the de facto Node.js library for image processing, used by Next.js, Gatsby, and most modern frameworks under the hood.
Install Sharp
npm install sharp
Convert a Single Image to AVIF and WebP
const sharp = require('sharp');
async function optimize(input) {
await sharp(input)
.resize({ width: 1600, withoutEnlargement: true })
.avif({ quality: 60 })
.toFile('output.avif');
await sharp(input)
.resize({ width: 1600, withoutEnlargement: true })
.webp({ quality: 75 })
.toFile('output.webp');
await sharp(input)
.resize({ width: 1600, withoutEnlargement: true })
.jpeg({ quality: 75, mozjpeg: true })
.toFile('output.jpg');
}
optimize('hero.png');
Generate Responsive Variants
Modern responsive design needs multiple sizes. Here’s a batch script that produces several widths in all three formats:
const sharp = require('sharp');
const sizes = [400, 800, 1200, 1600];
const formats = ['avif', 'webp', 'jpeg'];
async function generateVariants(input, name) {
for (const size of sizes) {
for (const fmt of formats) {
const pipeline = sharp(input)
.resize({ width: size, withoutEnlargement: true });
if (fmt === 'avif') pipeline.avif({ quality: 60 });
if (fmt === 'webp') pipeline.webp({ quality: 75 });
if (fmt === 'jpeg') pipeline.jpeg({ quality: 75, mozjpeg: true });
await pipeline.toFile(`./out/${name}-${size}.${fmt}`);
}
}
}
generateVariants('hero.png', 'hero');

Serving Optimized Images with the picture Element
Once you have AVIF, WebP and JPEG versions, use the <picture> element to let the browser pick the best one it supports:
<picture>
<source srcset="hero-1600.avif" type="image/avif">
<source srcset="hero-1600.webp" type="image/webp">
<img src="hero-1600.jpg" alt="Descriptive alt text"
width="1600" height="900" loading="lazy" decoding="async">
</picture>
Don’t forget:
- Always set width and height attributes to prevent layout shift.
- Use loading=”lazy” on below-the-fold images.
- Use fetchpriority=”high” on your LCP image instead of lazy loading.
- Write meaningful alt text for accessibility and SEO.
Quality Settings Cheat Sheet
After hundreds of tests, here are the quality values that consistently produce visually lossless results:
| Image Type | AVIF | WebP | JPEG (MozJPEG) |
|---|---|---|---|
| Photography | 55-65 | 75-80 | 75-82 |
| UI screenshots | 65-75 | 82-88 | 85-90 |
| Graphics with text | 70-80 | 85-90 | Use PNG/SVG |

Common Mistakes to Avoid
- Uploading 4000px wide images when the largest display size is 1200px. Always resize first.
- Using PNG for photos. PNG is for graphics with sharp edges, not photographs.
- Setting quality to 100. The difference between 100 and 80 is invisible. The difference in file size is enormous.
- Skipping the fallback. Even with great browser support, always provide a JPEG fallback for AVIF/WebP.
- Forgetting CDN cache headers. Optimized images should be cached aggressively (one year is fine if you version filenames).
FAQ
Should I use AVIF or WebP in 2026?
Use both. Serve AVIF first via the <picture> element with WebP as the second source and JPEG as the final fallback. AVIF gives the smallest files; WebP catches browsers that don’t yet support AVIF.
Is PNG or JPEG higher quality for web?
PNG is lossless and supports transparency, making it ideal for logos and graphics. JPEG is lossy but produces dramatically smaller files for photographs. For photos, JPEG (or better, WebP/AVIF) wins. For graphics with sharp edges and few colors, PNG wins.
Does 72 DPI matter for web images?
No. DPI is a print concept that has no effect on how an image displays on screen. What matters is the pixel dimensions and file size. You can safely ignore DPI settings for web work.
What’s the easiest way to optimize images without coding?
Squoosh.app is the simplest option for one-off images. For bulk work without code, tools like ImageOptim (Mac) or built-in WordPress plugins that use Sharp under the hood are great choices.
How much can I expect to reduce image file sizes?
Realistically, expect 50-70% reduction when moving from optimized JPEG to WebP, and another 30-50% when moving from WebP to AVIF, all without visible quality loss.
Wrapping Up
Optimizing images for web isn’t about finding one magic setting. It’s about layering three habits: pick the right format, resize to the displayed dimensions, and compress with sensible quality values. With Squoosh for quick wins and Sharp for automated pipelines, you have everything needed to make your site dramatically faster without sacrificing visual quality.
Start with one page. Run its hero image through Sharp. Generate AVIF, WebP and JPEG. Drop in a <picture> element. Measure the LCP improvement. Then roll it out across your site.

