Web Image Formats: Comparing JPEG, WebP, and AVIF

Images account for more than 60% of total transferred bytes on the average web page. Consequently, image optimization is the single most influential variable governing Google's Core Web Vitals—specifically Largest Contentful Paint (LCP). A hero image that takes two seconds to download on a mobile connection directly downgrades search ranking signals and user conversion rates.

For a measured browser conversion with downloadable input and output, follow our ImageSlim walkthrough. Check actual output MIME types rather than inferring encoder support from a requested extension.

1. The Compression Mechanics: How Modern Codecs Work

Legacy JPEG relies on the Discrete Cosine Transform (DCT) applied across static 8x8 pixel blocks. Because each block is processed in isolation, heavy compression causes visible "blockiness" and color banding across gradients.

Next-generation formats incorporate video compression innovations:

WebP (Derived from VP8 Video Codec)

Developed by Google and released in 2010, WebP utilizes predictive coding borrowed from the VP8 video keyframe format. Rather than compressing every block independently, WebP predicts pixel values in a block based on neighboring, previously decoded blocks. It subtracts the prediction from the actual image to create a residual, and encodes only that residual difference.

AVIF (Derived from AV1 Video Codec)

AVIF (AV1 Image File Format) is developed by the Alliance for Open Media (AOMedia)—a consortium comprising Google, Apple, Microsoft, Mozilla, Netflix, and Amazon. AVIF uses the intra-frame coding tools of the AV1 video codec.

The Decode Cost Trade-Off: CPU vs. Network

A smaller transfer can help loading, while decode cost and device speed also matter. Compare formats on representative devices and networks instead of assuming that AVIF always improves LCP.

2. Architectural Comparison Matrix

Feature / Metric JPEG (Legacy) WebP AVIF
Size vs JPEG for your content Baseline (100%) Measure your images Measure your images
Alpha Channel (Transparency) No Yes (Lossy & Lossless) Yes (Full 8/10/12-bit)
HDR & Wide Gamut Limited (8-bit sRGB) Limited (8-bit) Native (10/12-bit HDR)
Browser Decoding Overhead Very Low (Hardware) Low Medium to High
Global Browser Support Check current support Check current support Check current support

3. Multi-Format Responsive Delivery via HTML5 <picture>

Modern frontend engineering eliminates format dilemmas by leveraging the HTML5 <picture> element. The browser evaluates <source> elements in top-down order, picking the first MIME type it natively supports:

<picture>
  <!-- Serve ultra-compact AVIF to supporting browsers -->
  <source srcset="hero-image.avif" type="image/avif">

  <!-- Fallback to WebP for older browsers -->
  <source srcset="hero-image.webp" type="image/webp">

  <!-- Universal baseline fallback -->
  <img src="hero-image.jpg"
       alt="High Performance Architecture"
       width="1200"
       height="630"
       fetchpriority="high"
       loading="eager">
</picture>

Notice the inclusion of fetchpriority="high" and explicit width and height attributes. Explicit dimensions prevent Cumulative Layout Shift (CLS), while fetchpriority="high" instructs the browser's preload scanner to fetch the hero image immediately, which may improve resource prioritization; the actual LCP change must be measured.

4. Client-Side Image Transcoding with Canvas & WASM

Traditionally, converting images between formats required server-side processing using tools like ImageMagick or Libvips. Today, modern web applications can perform full image transcoding directly within the user's browser using HTML5 Canvas or WebAssembly (WASM).

The native Canvas API allows immediate export to WebP in JavaScript without external dependencies:

// Pure client-side conversion from File to WebP blob
async function convertToWebP(file, quality = 0.85) {
    const bitmap = await createImageBitmap(file);
    const canvas = document.createElement('canvas');
    canvas.width = bitmap.width;
    canvas.height = bitmap.height;

    const ctx = canvas.getContext('2d');
    ctx.drawImage(bitmap, 0, 0);

    return new Promise((resolve, reject) => {
        canvas.toBlob((blob) => {
            if (blob) resolve(blob);
            else reject(new Error('Canvas export failed'));
        }, 'image/webp', quality);
    });
}

Conclusion

Use modern formats when their measured size, visual quality, compatibility, and decode performance suit your page. Neither byte savings nor an LCP improvement is guaranteed by a format name alone.

To convert your images between WebP, PNG, JPEG, and next-gen formats right inside your browser without uploading your photos to remote servers, explore our Photo Convert and ConvertEase tools.

References

Sudarshan Babar

Sudarshan Babar

Founder & Lead Developer at getinfotoyou. Specialized in full-stack web architecture, client-side algorithm engineering, and transparent personal finance modeling.