WebP Optimization Guide
Best practices for optimizing WebP images for maximum web performance and compatibility.
By the CompressItAll team. Published 2025-11-22. Updated 2026-10-24.
What This Guide Covers
This is the practical side of WebP: deciding what to convert, picking settings, writing markup with fallbacks, and checking that the change helped. It does not explain how the codec works, which is in How WebP Compression Works, and it does not argue for or against the format in the first place. That decision is in WebP vs PNG vs JPEG. If you are considering AVIF as well, the AVIF, WebP and JPEG comparison covers it.
Quick Optimization Checklist
- Start from the original file, not from an earlier compressed copy
- Resize to the displayed size before converting
- Choose lossy for photographs and lossless for flat graphics
- Compare file sizes against the existing JPEG or PNG, and keep the smaller one that still looks right
- Serve WebP with a fallback through
pictureor content negotiation - Set width and height, and lazy load only below the fold
- Measure the page before and after
1. Choosing Lossy vs Lossless
Use Lossy WebP For:
- Photographs and realistic images
- Large hero or banner images
- Product photos where a small file matters
- Transparent photos, such as cut-out products on a coloured page
Use Lossless WebP For:
- Logos, icons and UI artwork with flat colour
- Screenshots and diagrams with text
- Master copies where every pixel must survive
A common mistake is to run a screenshot through lossy WebP and then wonder why the text looks fuzzy. If the image has hard edges and few colours, use lossless. If it is a photograph, lossy is almost always the right starting point.
2. Quality Settings to Test
The scale runs from 0 to 100, but the number is an encoder setting, not a promise about appearance. Use the table as a first guess and confirm by looking.
| Setting | Use it for | Watch for |
|---|---|---|
| Lossless | Graphics, screenshots, masters | Photos may produce larger files than lossy |
| Lossy, higher quality (about 85-90) | Hero images, product photos, portfolios | Diminishing returns; the file keeps growing |
| Lossy, middle (about 75-85) | General web photos, a good first test | Soft detail in textured areas |
| Lossy, lower (about 60-70) | Thumbnails and backgrounds, judged case by case | Smearing, blocking and banding |
3. Responsive Images with srcset
Serving one large file to every visitor wastes data on small screens. Provide several widths and let the browser choose:
<picture>
<source
type="image/webp"
srcset="
hero-400w.webp 400w,
hero-800w.webp 800w,
hero-1200w.webp 1200w,
hero-1600w.webp 1600w"
sizes="(max-width: 640px) 100vw,
(max-width: 1024px) 80vw,
1200px">
<img
src="hero-1200w.jpg"
alt="Hero image"
loading="lazy"
width="1200"
height="600">
</picture>The sizes attribute tells the browser how wide the image will be at each breakpoint, so it can pick a file before layout finishes. If sizes is wrong, the browser may download a larger file than needed. Note that the example above uses loading="lazy"; remove it if this is the first large image on the page.
4. Fallbacks and Compatibility
Current Chrome, Firefox, Safari and Edge all support WebP. A fallback is still sensible for old embedded browsers, email clients, and tools that import images, such as some document editors and social preview crawlers.
Method 1: Picture Element (Recommended)
<picture>
<source srcset="image.webp" type="image/webp">
<source srcset="image.jpg" type="image/jpeg">
<img src="image.jpg" alt="Description">
</picture>Method 2: Server-Side Detection
Check the Accept header for image/webp and serve WebP when supported:
// Example: Express.js middleware
app.use((req, res, next) => {
if (req.headers.accept?.includes('image/webp')) {
req.supportsWebP = true;
}
next();
});The markup approach is easier to cache and has no server logic. Server-side detection keeps the HTML simpler but must be paired with a Vary: Accept header, covered below.
5. Lazy Loading
Defer images that start below the first screen. Always include width and height so the browser can reserve space and avoid layout shift. Do not lazy load the main image at the top of the page, since it is usually what visitors wait for. Native lazy loading needs no script.
<picture>
<source srcset="image.webp" type="image/webp">
<img
src="image.jpg"
alt="Description"
loading="lazy"
width="800"
height="600">
</picture>6. Preparing Sources
- Resize first. Pixel count affects size more than any setting.
- Avoid converting twice. Going from JPEG to lossy WebP stacks one lossy step on another. Start from the original when you have it.
- Strip metadata you do not need, especially location data, and check orientation afterwards.
- Mind transparency. If a PNG has an alpha channel, keep it. Lossy WebP can store alpha, and lossless WebP stores it exactly.
7. Convert with Our Tool
The WebP compressor accepts PNG, JPEG, WebP and AVIF files, up to 5 per batch. Choose Lossless or Lossy (quality default 85). Custom mode has quality, target size and dimension fields, but they are not applied reliably yet, so check the final size in the results table. Use the before and after view to inspect edges, text and gradients, then download each file or a ZIP. Uploads go to our servers over HTTPS and are deleted automatically after processing. No registration is needed.
8. Build Process Integration
For a site with many images, generate WebP in the build instead of by hand:
Using Sharp (Node.js):
const sharp = require('sharp');
// Lossy WebP
await sharp('input.jpg')
.webp({ quality: 80 })
.toFile('output.webp');
// Lossless WebP
await sharp('input.png')
.webp({ lossless: true })
.toFile('output.webp');Using Next.js:
// next.config.js
module.exports = {
images: {
formats: ['image/webp', 'image/avif'],
deviceSizes: [640, 750, 828, 1080, 1200],
},
};Note that the Next.js image optimiser needs a server or a loader. A fully static export does not run it, so pre-generate the files in that case.
9. CDN and Caching
- Cache headers: Use long cache lifetimes for files whose names change when content changes.
- Vary header: Include
Vary: Acceptwhen one URL returns different formats by browser support, or a cache may hand the wrong format to a client. - CDN conversion: Some CDNs convert on the fly. Check that the conversion keeps your quality choice.
10. Testing
- Compare the WebP with the original at the display size and at 100 percent.
- Confirm it is actually smaller than the JPEG or PNG it replaces.
- Run Lighthouse or PageSpeed Insights before and after, and note the Largest Contentful Paint element.
- Test the fallback by blocking WebP in a test setup or using an old browser.
- Check on a phone with a slow connection profile.
Troubleshooting
| Problem | Likely cause | Fix |
|---|---|---|
| WebP is larger than the JPEG | Lossless mode on a photo, or quality set high | Use lossy and lower the quality, or keep the JPEG |
| Text looks fuzzy | Lossy on a screenshot | Switch to lossless |
| Wrong format served from cache | Missing Vary header | Add Vary: Accept or use picture |
| Image missing in an old app or email | No WebP support in that client | Provide a JPEG or PNG there |
| Layout jumps as images load | No width and height | Set both attributes |
Common Pitfalls
- Converting every JPEG to WebP blindly without comparing the sizes.
- Serving WebP with no fallback where old clients matter.
- Using very low quality for customer-facing images because the file looked small.
- Keeping WebP as the only copy of an image that will be edited again. Store a source file.
- Lazy loading the first image on the page.
What to Expect
For photographs, WebP is often smaller than JPEG at a similar appearance, and for graphics, lossless WebP is often smaller than PNG. The size of the gain varies by image and encoder, so measure it for your own files. Lighter images can help Core Web Vitals, particularly Largest Contentful Paint when an image is the largest element, but they are only one factor in page speed. Related reading: JPEG Optimization Guide for the fallback files, and Batch Compression Guide for processing many images.
Start Optimizing WebP Images
Use our free online WebP compressor with Lossless, Lossy and Custom modes and batches of up to 5 files. No registration required.
Compress WebP Images Now →