🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///

AVIF: Pushing Compression Further, Layered Safely

Learn how AVIF's AV1 video-codec-derived compression achieves superior file sizes, the build-time (not runtime) encoding-speed tradeoff involved, and how to construct a full AVIF-WebP-JPEG fallback chain.

Total XP: 0|💻 html XP: 0

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

AVIF Format

Max compression, layered safely.


🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.

AVIF represents the current frontier of practical image compression, often beating even WebP significantly — understanding its real tradeoffs and how to layer it safely alongside WebP and JPEG completes a genuinely future-proof image strategy.

1Where AVIF's Compression Advantage Comes From

AVIF stands for 'AV1 Image File Format' — it directly reuses compression techniques developed for the AV1 video codec, applying them to individual still images. Video compression research tends to be unusually sophisticated and well-funded, since video's vastly larger data volume creates strong commercial incentive for even small efficiency percentage gains, and AVIF is a direct beneficiary of that research being repurposed for still images.

The practical result: AVIF often produces files 20-50% smaller than an equivalent WebP file at comparable visual quality, and even more dramatically smaller than equivalent JPEG — a meaningful additional step beyond the already-significant WebP improvement covered in the previous lesson.

// AVIF often achieves 20-50% smaller files than
// equivalent-quality WebP, on top of WebP's own JPEG savings
localhost:3000
✓ Compounding Savings Over JPEGAVIF's advantage over WebP stacks on top of WebP's already-significant advantage over JPEG.

2The Real Tradeoff: Build-Time Encoding Speed

AVIF's compression sophistication isn't free — encoding an image to AVIF typically takes meaningfully longer than encoding the same image to WebP or JPEG, sometimes significantly so for high-quality settings on large images. This is an important practical consideration for build pipelines processing many images, where total encoding time can become a real CI/CD duration concern.

Critically, this cost is entirely a build-time/optimization-pipeline concern — it has zero impact on end users, who simply download the resulting (smaller) file and have it decoded and displayed at normal speed by their browser, with no runtime penalty whatsoever from the format choice itself.

// Build pipeline: AVIF encoding takes longer
// End user: downloads a smaller file, decodes normally, zero penalty
localhost:3000
Cost location:
Build pipeline only — never the end user

3Constructing A Complete AVIF-WebP-JPEG Chain

Given AVIF's still-maturing (though rapidly growing) browser support relative to WebP's near-universal support, the safest and most future-proof production pattern layers all three formats within a single <picture> element, ordered from most-preferred to most-compatible: AVIF first, WebP second, and a JPEG or PNG <img> fallback last.

The browser automatically selects the first <source> it can actually decode, meaning the newest browsers download the smallest possible AVIF file, browsers with only WebP support get that intermediate-sized file, and every remaining browser still gets a fully functional, universally-compatible fallback — capturing the maximum available savings for each individual user's actual browser capability.

<picture>
  <source type="image/avif" srcset="photo.avif">
  <source type="image/webp" srcset="photo.webp">
  <img src="photo.jpg" alt="...">
</picture>
localhost:3000
✓ Best Available Format Per Browser, AutomaticallyEvery visitor receives the smallest format their browser can actually decode, with zero detection logic.

4Step-by-Step Breakdown

The Next Step Beyond WebP. AVIF, based on the AV1 video codec, typically pushes compression even further than WebP — often producing files 20-50% smaller still at comparable visual quality — at the cost of newer, less universal browser support and, notably, slower encoding time.

AVIF Derives From A Video Codec's Compression Techniques. Unlike WebP or JPEG, which were designed specifically as still-image formats, AVIF reuses the compression techniques from the AV1 video codec — video compression research tends to be extremely sophisticated, since video's larger data volume creates strong incentive for efficiency gains, and AVIF inherits those benefits.

AVIF's Technical Origin. Why does AVIF often achieve better compression than formats designed specifically as still-image formats?

  • It's coincidental with no real technical explanation
  • It reuses highly sophisticated compression techniques from the AV1 video codec
  • It simply uses lower quality settings by default

The Tradeoff: Slower Encoding Time. AVIF's superior compression comes with a real cost during the build/optimization pipeline: encoding an AVIF file typically takes meaningfully longer than encoding an equivalent WebP or JPEG — a build-time cost, not a runtime one, but worth accounting for in CI/CD pipeline planning.

AVIF's Encoding Tradeoff. Does AVIF's slower encoding time affect how quickly an end user's browser can display the image?

  • Yes, images take noticeably longer to display once downloaded
  • No, the slower encoding is a one-time build/optimization cost, not a runtime viewing cost
  • It affects both encoding and the end-user viewing experience equally

Layering AVIF Into A Full Fallback Chain. Since AVIF has newer, less universal support than WebP, the safest production pattern layers all three formats within one <picture> element: AVIF first (best compression, for the newest browsers), WebP second (broad modern support), and JPEG/PNG last (universal fallback).

Full Format Fallback Chain. In a <picture> element offering AVIF, WebP, and JPEG, what determines the correct order to list the <source> elements?

  • Alphabetical order of the format names
  • Most preferred/best-compressed format first, down to the most universally-supported fallback last
  • Order doesn't matter at all

AVIF Understood. You now understand AVIF's video-codec-derived compression advantage over WebP, the build-time (not runtime) encoding-speed tradeoff, and how to layer AVIF, WebP, and JPEG together in a single, safe, best-to-broadest fallback chain — completing the Modern Images module.

Offer An AVIF Source. <picture> lets the browser pick the most efficient format it supports, falling back otherwise.

Level Up 🚀

Advanced cheat sheets, SEO tricks, and interview prep for this topic.

Browser Support

ChromeSupported

Fully supported.

FirefoxSupported

Fully supported.

SafariSupported

Fully supported.

EdgeSupported

Fully supported.

Accessibility (A11y)

1The Full AVIF/WebP/JPEG Fallback Chain Still Relies On A Single alt Attribute On The Final <img>

Regardless of how many format layers are offered, accessibility naming remains consistent and simple — one accurate alt value on the fallback <img> covers every possible format outcome.

SEO Implications

  • 1

    A Full AVIF-WebP-JPEG Chain Represents The Current Maximum Practical Image-Weight Optimization Available In Pure HTML

    Combined with correctly-implemented srcset/sizes for resolution switching, this represents essentially the complete, current best-practice image optimization strategy achievable without server-side or CDN-level tooling.

Best Practices

Order <source> Elements From Most-Preferred (Best Compression) To Most-Compatible (Universal Fallback)

Since the browser selects the first supported source, correct ordering ensures every user automatically receives the smallest file their specific browser is actually capable of decoding.

Account For AVIF's Longer Encoding Time When Planning Build Pipeline Duration For Large Image Sets

It's a real, practical build-time cost worth budgeting for, even though it has zero impact on end-user experience — surprising teams during their first large-scale AVIF rollout otherwise.

Frequent Bugs

THE BUG

A CI/CD image optimization step takes significantly longer after adding AVIF encoding to the pipeline.

THE FIX

This is an expected build-time tradeoff of AVIF's more sophisticated compression; consider parallelizing encoding or scoping AVIF generation to only the highest-traffic images if pipeline duration becomes a real constraint.

THE BUG

A <picture> element lists WebP before AVIF in its <source> order.

THE FIX

Reorder <source> elements from most-preferred (AVIF) to most-compatible (JPEG fallback), since the browser selects the first source it can decode.

Real-World Examples

Complete Three-Format Fallback Chain

A production hero image offering the maximum practical compression across every visitor's browser capability.

<picture>
  <source type="image/avif" srcset="hero.avif">
  <source type="image/webp" srcset="hero.webp">
  <img src="hero.jpg" alt="Product dashboard overview" width="1200" height="600">
</picture>

Interview Prep

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Common Pitfalls & Errors

The Error //

Listing <source> elements in the wrong order (WebP before AVIF)

<picture> <source type="image/avif" srcset="photo.avif"> <source type="image/webp" srcset="photo.webp"> <img src="photo.jpg" alt="..."> </picture>

The Solution //

Order from most-preferred to most-compatible: AVIF, then WebP, then the universal fallback.

The Error //

Not accounting for AVIF's longer encoding time in build pipeline planning

<!-- AVIF encoding is a build-time cost, plan accordingly -->

The Solution //

Budget additional CI/CD time for AVIF encoding, or parallelize/scope it appropriately for large image sets.

Lesson Glossary

[01]AVIF

AV1 Image File Format, a highly efficient modern format.

Code Preview
Often 20-50% smaller than WebP

[02]AV1

The video codec AVIF's compression techniques derive from.

Code Preview
Video codec origin

[03]Encoding Time

The build-time cost of compressing an image to a format.

Code Preview
AVIF: slower to encode

[04]Fallback Chain

Multiple <source> formats ordered best-to-broadest.

Code Preview
AVIF → WebP → JPEG

Continue Learning