LESSON 20 · INTERMEDIATE4 min read

Next-Gen Image Formats: AVIF, WebP, and Progressive Fallbacks

Optimize image delivery pipelines: AVIF (AV1 Still Image File Format), WebP, multi-format progressive enhancement with <picture type="...">, and compression trade-offs.

HTML5 / Living StandardFree to readModule 5 of 8
YOUR NEXT SMALL WINS

By the end, you’ll be able to…

  • Contrast next-gen formats (AVIF, WebP) with legacy formats (JPEG, PNG, GIF) in compression efficiency and feature support
  • Implement multi-format progressive fallback chains using <picture> and type attributes
  • Evaluate compression artifacts (chroma subsampling, banding) and decoding performance

01The Evolution of Web Image Compression

Images account for over 60% of total byte payload on typical web pages. For decades, the web relied on formats developed in the 1990s: JPEG (lossy photographic compression), PNG (lossless graphics with alpha transparency), and GIF (limited 256-color animations).

Modern web engineering utilizes two modern next-generation formats:

1. WebP: Developed by Google. Delivers 25-35% smaller file sizes than comparable JPEG images while supporting both lossy and lossless compression, alpha transparency, and animations.

2. AVIF (AV1 Image File Format): Derived from the open-source AV1 video codec. Delivers up to 50% smaller file sizes than JPEG and 20% smaller than WebP at identical visual fidelity. Supports 10-bit and 12-bit High Dynamic Range (HDR) color depth, wide color gamuts (P3), and exceptional dark-region fidelity without banding.

index.htmlHTML
<!-- Multi-Format Progressive Enhancement --><picture>    <!-- 1. Preferred: AVIF (Smallest payload, modern browsers) -->    <source type="image/avif"             srcset="product-hero.avif">        <!-- 2. Fallback: WebP (Broad support across older browsers) -->    <source type="image/webp"             srcset="product-hero.webp">        <!-- 3. Universal Base Fallback: Highly optimized JPEG -->    <img src="product-hero.jpg"          alt="Ultra-light titanium mechanical watch"         width="1000" height="600"         loading="lazy"         decoding="async"></picture>

02Progressive Format Fallback Architecture

Because older browsers or corporate environments may lack AVIF decoders, web developers must never serve raw AVIF images exclusively in an <img> tag without fallbacks.

The <picture> element provides native, declarative format negotiation through the type attribute on <source> elements (e.g. type="image/avif").

The browser evaluates the <source> tags in exact top-to-bottom order. If the browser engine supports AVIF, it downloads the .avif file and ignores all subsequent tags. If unsupported, it steps down to WebP. If WebP is unsupported, it falls back to the baseline <img> JPEG. This provides bleeding-edge compression with 100% backward compatibility.

03decoding="async" and Off-Thread Decoding

Image decoding—converting compressed byte streams into raw RGB pixel bitmaps in memory—can be computationally intensive. By default, decoding can pause the browser's main thread during scrolling.

Adding decoding="async" to <img> tags instructs the browser to decode image bitmaps asynchronously on a background worker thread, ensuring silky-smooth 60fps / 120fps scrolling even on low-end mobile devices.

04Image Format Comparison Matrix

A comparison of web image formats and compression efficiencies:

Adopt AVIF as primary format with WebP and JPEG fallbacks for maximum performance.

notes.txtPlain text
+-----------------------+---------------------+-------------------+-------------------------+| Format                | Compression Type    | Transparency      | Relative Payload Size   |+-----------------------+---------------------+-------------------+-------------------------+| AVIF                  | Lossy / Lossless    | Yes (Full Alpha)  | 100% (Baseline Smallest)|| WebP                  | Lossy / Lossless    | Yes (Full Alpha)  | ~125% of AVIF           || JPEG                  | Lossy Only          | No Transparency   | ~200% of AVIF           || PNG                   | Lossless Only       | Yes (Full Alpha)  | ~350% of AVIF (Graphics)|+-----------------------+---------------------+-------------------+-------------------------+

05Production Standards & Real-World Engineering Trade-Offs

Modern digital experiences demand high-fidelity visual assets delivered with minimal bandwidth consumption. In responsive web design, serving desktop-sized raster images to mobile devices wastes megabytes of user cellular data and triggers memory pressure on low-power devices. Leveraging the picture element and srcset attributes ensures that the browser requests only the exact resolution matching the viewport and device pixel ratio.

Furthermore, scalable vector graphics (SVG) provide mathematically resolution-independent visuals with near-zero byte footprints. When embedded inline within HTML documents, SVGs become fully scriptable and styleable via CSS, allowing developers to craft dynamic micro-animations, interactive vector dashboards, and theme-adaptive brand assets without additional network requests.

LET IT CLICK

The ideas worth keeping.

  • AVIF offers industry-leading compression efficiency with full HDR and alpha channel support.
  • Use <picture> with type="image/avif" and type="image/webp" to deliver modern formats safely.
  • Add decoding="async" to prevent image decompression from dropping animation frames on the main thread.
TURN UNDERSTANDING INTO SOMETHING YOU CAN DO

Make it yours.

Edit the starter, press Preview, and see your page render in the browser preview. Compare with the worked solution when ready.

01

Exercise 1: Write a picture element delivering a hero b

Write a <picture> element delivering a hero banner in AVIF, falling back to WebP, and finally falling back to a standard JPEG <img>.

your_turn_1.html🌐HTML
Ctrl + ↵
Preview
Press Preview to render your page
Press Preview to render your HTML in the browser preview.
Explore a worked solution
one_possible_solution.htmlHTML
<picture>    <source type="image/avif" srcset="banner.avif">    <source type="image/webp" srcset="banner.webp">    <img src="banner.jpg"          alt="Modern distributed cloud datacenter"         width="1200" height="500"         loading="lazy"         decoding="async"></picture>

Order sources: AVIF first, WebP second, <img> JPEG last.

02

Exercise 2: Explain why decoding async improves user ex

Explain why decoding="async" improves user experience during page scrolling.

your_turn_2.html🌐HTML
Ctrl + ↵
Preview
Press Preview to render your page
Press Preview to render your HTML in the browser preview.
Explore a worked solution
one_possible_solution.htmlHTML
// Decoding compressed image formats (like AVIF and JPEG) into uncompressed pixel bitmaps// requires significant CPU processing. By default, synchronous decoding occurs on the browser's main thread,// which can drop frames and cause stutter during fast user scrolling.// decoding="async" moves image decoding to background threads, keeping the main thread free for smooth 60fps scrolling.

Asynchronous decoding moves bitmap decompression off the browser's main thread.

A SMALL QUESTION. A USEFUL NEXT STEP.

What stayed with you?

Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.

A LITTLE ACTIVE RECALL0 / 3 answered
01Which modern image format generally achieves the highest compression efficiency (smallest byte footprint) at high visual quality?
02How does a browser decide which <source> to download inside a <picture> element?
03What is the primary benefit of the decoding="async" attribute on an <img> tag?

Keep exploring.

The official references behind this lesson, when you want a second angle or the full details.

One lesson closer.

Reading is a start. Trying it yourself makes the connection.

Completion is saved in this browser. It records reading and hands-on practice progress.