JPEG vs PNG vs WebP vs AVIF: When to Use Each Image Format
Images are typically the heaviest assets on a web page, and the format choice alone can halve โ or double โ their weight. The landscape has settled into four serious options, each with a clear job. Picking wrong doesn't just waste bandwidth: it costs you transparency, animation, or compatibility with a chunk of your visitors.
The Two Compression Philosophies
Lossy compression (JPEG, WebP-lossy, AVIF) discards information the encoder judges imperceptible, achieving much smaller files. Quality is a dial: turn it down, files shrink and artifacts grow. Every re-save of a lossy file degrades it further โ never use lossy formats as working masters.
Lossless compression (PNG, WebP-lossless) preserves every pixel exactly. Files are bigger, but you can edit and re-save forever. PNG additionally supports an alpha channel (transparency); classic JPEG does not.
The right question is never "which format is best" โ it's "what does this image need": photographic detail, sharp edges and text, transparency, animation?
The Four Formats
JPEG: the photographic workhorse
JPEG (1992) uses the discrete cosine transform: the image is split into 8ร8 blocks, each block is expressed as a sum of cosine waves, and high-frequency detail (which eyes notice least) is quantized away aggressively. That's why JPEG artifacts look like blocky smearing around sharp edges โ the 8ร8 grid showing through.
- Best for: photographs and complex gradients โ anywhere with smooth tonal variation and no sharp edges.
- No transparency, no animation. Text and line art compress badly (ringing artifacts around edges).
- Universally supported. Every browser since forever.
PNG: the pixel-perfect choice
PNG uses DEFLATE compression (the same family as gzip) on filtered pixel data โ fully lossless. It supports full alpha transparency and is the default for anything requiring exact pixels.
- Best for: screenshots, logos, UI elements, diagrams, images with text, anything needing transparency.
- Files are large for photographic content โ often 3โ5ร a comparable JPEG. Never use PNG for photos.
- Universally supported, including animation via APNG (supported in all modern browsers, though rarely used).
WebP: the pragmatic modern default
WebP (Google, 2010) does both lossy (based on VP8 video codec intra-frame coding) and lossless compression, plus alpha and animation. In practice, WebP-lossy runs 25โ35% smaller than JPEG at equivalent visual quality, and WebP-lossless runs ~25% smaller than PNG.
- Best for: almost everything on the web today โ photos, transparency, simple animation.
- Supported in all modern browsers since ~2020 (Safari added it in 14.0). The remaining gaps are old email clients and some native apps.
- Encoding is slower than JPEG, but that's a build-time cost, not a user-facing one.
AVIF: the new efficiency king
AVIF (2019) uses the AV1 video codec's intra-frame coding. It delivers ~50% smaller files than JPEG at the same visual quality, with better detail preservation at very low bitrates. It supports HDR, wide color gamut, alpha, and animation.
- Best for: photographic content where every byte counts โ hero images, galleries, image-heavy feeds.
- The catch: encode/decode cost. AVIF encoding is dramatically slower than JPEG/WebP (seconds per image at high effort settings), and software decoding is heavier on low-end devices. For thumbnails generated on the fly, that CPU cost matters.
- Support is broad in modern browsers (Chrome, Firefox, Safari 16+), but older clients fall back โ always serve with a fallback chain.
Decision Flowchart
Does it need transparency?
โโ Yes โ Is it photographic with transparency?
โ โโ Yes โ WebP (or AVIF if the audience is modern)
โ โโ No (logo, UI, text) โ PNG or WebP-lossless
โโ No โ Is it animated?
โโ Yes โ WebP (or video: MP4/WebM is far more efficient for long animation)
โโ No โ Is it a photo / complex gradient?
โโ Yes โ AVIF (modern) with WebP fallback, or WebP alone
โโ No (screenshot, diagram, text) โ PNG or WebP-lossless
And serve it correctly with the <picture> element so every browser gets the best format it understands:
<picture>
<source srcset="hero.avif" type="image/avif">
<source srcset="hero.webp" type="image/webp">
<img src="hero.jpg" alt="Product hero shot" width="1200" height="800">
</picture>
The browser picks the first supported format; ancient clients get the JPEG. This one pattern captures nearly all of AVIF/WebP's benefit with zero compatibility risk.
Quality Settings That Actually Matter
- JPEG: quality 75โ85 is the sweet spot for photos. Below ~60, blocking artifacts become obvious; above ~90, files balloon for invisible gains. Progressive JPEG (
-progressive) renders a blurry preview first โ better perceived performance. - WebP lossy: quality 75โ80 roughly matches JPEG 85 at much smaller sizes.
- AVIF: quality 50โ60 (the scales differ per encoder) with effort/speed 4โ6 for a sane encode-time ratio. At very low bitrates AVIF degrades far more gracefully than JPEG โ no block grid, just softness.
- PNG: run through a compressor (
oxipng,pngquant). PNG files from design tools are routinely 30โ70% larger than necessary. For photographic-ish PNGs where exact pixels don't matter, consider lossy PNG (pngquantdoes palette reduction โ often 60%+ smaller, visually identical).
Also: strip metadata. Photos carry EXIF (camera model, GPS coordinates, thumbnails) โ stripping it saves kilobytes and avoids leaking location data. And serve responsive sizes (srcset): a 2400px hero delivered to a 375px phone wastes ~90% of its bytes regardless of format.
Common Mistakes
1. PNG for photographs. The most common image-weight bug on the web. A photo saved as PNG is routinely 3โ5ร larger than the same photo as JPEG/WebP. If it has no transparency and no sharp text, it shouldn't be PNG.
2. JPEG for screenshots and text. JPEG's 8ร8 blocks smear sharp edges โ text screenshots become blurry and larger than PNG would be. Screenshots are PNG/WebP-lossless territory.
3. No fallback chain. Serving AVIF without WebP/JPEG fallbacks breaks older browsers outright. The <picture> element exists for exactly this.
4. Re-compressing lossy files. Downloading a JPEG and re-saving it as WebP bakes in the JPEG artifacts plus new WebP artifacts. Always convert from the highest-quality master.
5. Ignoring decode cost. AVIF's smaller files come with heavier decoding. On low-end mobile devices, a page full of AVIFs can jank scrolling. Measure with real devices, not just file sizes.
6. Forgetting dimensions. Always set width and height (or aspect-ratio) on images. Without them, the page layout shifts when images load (Cumulative Layout Shift) โ a Core Web Vitals penalty no format choice can fix.
Debugging Walkthrough: "The Images Look Worse After Conversion"
- Compare at 100% zoom, side by side. Thumbnails hide artifacts; full-size reveals them. Check edges (text, logos) and gradients (banding) specifically.
- Check the quality parameter. Converters have different default scales โ "quality 80" in one tool isn't "quality 80" in another. AVIF scales in particular differ from JPEG scales.
- Look for double lossy. If the source was already a JPEG, some quality loss is baked in. Convert from the original master, not from the JPEG.
- Inspect chroma subsampling. JPEG's default 4:2:0 subsampling throws away 3/4 of color resolution โ fine for photos, destructive for red text on black. For graphics, use 4:4:4 or a lossless format.
- Verify the fallback actually served. DevTools network panel: check the
Content-Typeof what the browser received. A misconfigured server may serve AVIF bytes with a JPEG content type (or vice versa).
Try It
Before converting formats, shrink what you have. DailyToolbox's free image compressor runs entirely in your browser โ compress JPEG, PNG, and WebP images locally, compare quality side by side, and strip metadata without uploading anything.
FAQ
Is AVIF going to replace JPEG?
For new content on modern browsers, increasingly yes โ the size savings are too large to ignore. But JPEG's universality (email clients, old devices, every tool ever written) means it stays as the fallback for years. Think "AVIF first, JPEG fallback," not "JPEG is dead."
What's the difference between WebP and WebP2?
WebP2 was Google's experimental successor with ~30% better compression, but it was never finalized or shipped in browsers โ development stalled and AVIF won the "next format" race instead. Don't wait for WebP2; it isn't coming.
Should I use SVG instead of PNG for logos?
Yes, whenever possible. SVG is vector โ infinitely scalable, tiny for geometric artwork, and styleable with CSS. PNG is for logos only when you need pixel-exact rendering of complex raster artwork or must support ancient clients without SVG.
Does converting JPEG to WebP/AVIF improve quality?
No. Conversion never adds quality โ at best it preserves it at a smaller size. A WebP converted from a low-quality JPEG contains the JPEG's artifacts. Quality only ever flows downhill; keep your masters lossless.
How much smaller is AVIF really?
At matched visual quality (measured by SSIM/VMAF studies, including Netflix's well-known comparisons), AVIF averages roughly 50% smaller than JPEG and ~20โ30% smaller than WebP. Your mileage varies by content โ detailed textures favor AVIF most; simple graphics show smaller gaps.