DEV Community

zhiwei wang
zhiwei wang

Posted on

JPEG vs WebP vs AVIF: A Practical Guide to Image Formats in 2026

If you've ever stared at a Lighthouse report and wondered why your "Performance" score refuses to move, the answer is usually sitting right in front of you: the images. On a typical content-heavy page, images are often the heaviest assets on the page, and the single biggest lever you have is choosing the right format and the right compression settings.

Here's a practical, no-fluff guide to the three formats that matter in 2026 — JPEG, WebP, and AVIF — and how to actually use them.

What each format is actually good at

JPEG — the universal workhorse

JPEG has been around since 1992, and every browser made in the last quarter century supports it. It's a lossy format designed for photographs: it throws away subtle detail the human eye is unlikely to notice in order to shrink the file.

  • Best for: photos, hero images, and anything where you need a guaranteed fallback.
  • Strengths: universal support, simple, predictable.
  • Weaknesses: no transparency, and at small file sizes you start seeing blocky compression artifacts.

WebP — the modern default

WebP was introduced by Google and supports both lossy and lossless compression, plus transparency (alpha channel) and even animation. At a comparable visual quality, a lossy WebP is usually noticeably smaller than an equivalent JPEG.

  • Best for: the everyday format for most web images.
  • Strengths: good compression, transparency, very wide support.
  • Weaknesses: a tiny fraction of very old browsers still don't support it, so a fallback is prudent.

AVIF — the next-generation option

AVIF is based on the AV1 video codec and is the most efficient of the three. It handles both lossy and lossless, supports transparency, and does especially well with high-detail photos and even HDR content. At the same visual quality, AVIF files are often the smallest.

  • Best for: squeezing the most out of large photographic images and modern sites.
  • Strengths: excellent compression, modern feature set.
  • Weaknesses: encoding is slower, and support is newer than WebP — so you still want fallbacks.

Quick rule of thumb

Format Lossy / Lossless Transparency Typical use
JPEG Lossy No Universal fallback, photos
WebP Both Yes Default for most web images
AVIF Both Yes Best compression, modern browsers
PNG Lossless Yes Logos, screenshots, graphics

Notice I kept PNG in the table: for photos it's usually overkill, but for clean graphics, logos, and screenshots with sharp edges and text, a well-optimized PNG (or indexed-color PNG-8) is still the right tool.

How to use them in real markup

The cleanest pattern is the <picture> element, which lets the browser pick the first format it understands and falls back to JPEG if it understands none:

<picture>
  <source srcset="hero.avif" type="image/avif" />
  <source srcset="hero.webp" type="image/webp" />
  <img
    src="hero.jpg"
    alt="A mountain lake at sunrise"
    width="1600"
    height="900"
    loading="lazy"
  />
</picture>
Enter fullscreen mode Exit fullscreen mode

The browser downloads only the first source it can decode, so you don't pay for the others. The plain <img> inside is what makes this work everywhere and keeps your alt text in one place.

Don't forget responsive sizes

Format is only half the battle. Serving a 3000px-wide hero to a phone on a cellular connection is wasteful no matter how well it's compressed. Use srcset to hand the browser appropriately sized options:

<img
  src="hero-800.jpg"
  srcset="hero-800.jpg 800w, hero-1200.jpg 1200w, hero-1600.jpg 1600w"
  sizes="(max-width: 600px) 100vw, 50vw"
  alt="A mountain lake at sunrise"
  loading="lazy"
/>
Enter fullscreen mode Exit fullscreen mode

Protect your LCP

For the single largest above-the-fold image (often the hero), a couple of small tweaks help the browser prioritize it:

<img src="hero.avif" alt="..." fetchpriority="high" />
Enter fullscreen mode Exit fullscreen mode

And reserve space with width and height attributes so the layout doesn't shift while the image loads — that helps both performance and Cumulative Layout Shift.

Picking quality settings

Modern formats are forgiving, and most people over-estimate the quality they need. A sensible starting point:

  • JPEG: quality around 60–75
  • WebP: quality around 65–75
  • AVIF: quality around 45–55 (its scale behaves differently, lower numbers go further)

The right method is always the same: make a copy, try a few settings, and compare at 100% zoom. Push compression until you can just start to notice a difference, then back off one notch. The goal is the smallest file that still looks indistinguishable to a normal viewer — not the highest possible number.

A note on privacy

One detail people overlook: many online compressors upload your files to a server to process them, and some retain copies for a period. If you're handling confidential designs, client work, or personal photos, that's a real consideration. A browser-based compressor that runs entirely client-side (using WebAssembly) never uploads the file in the first place, which removes that class of risk entirely.

I've been building exactly this — Eltorin is a free image compressor that does all the processing locally in your browser with no uploads, no signup, and no artificial file-count or size quotas. It handles JPEG, PNG, WebP, and AVIF, and it's a handy way to experiment with the quality settings above without sending anything anywhere.

The takeaway

  1. Default to WebP, use AVIF for maximum savings on modern browsers, and keep a JPEG fallback.
  2. Use <picture> for format negotiation and srcset for responsive sizes.
  3. Reserve image dimensions, lazy-load below the fold, and mark your LCP image with fetchpriority="high".
  4. Tune quality by eye — the smallest file that looks identical is the winner.

Get the images right, and that stubborn performance score usually starts taking care of itself.


Top comments (0)