Skip to main content
Beta: Front-End Checklist is currently in beta. Some issues are still being fixed. Thanks for your patience.

Use AVIF format for modern browsers

Images support AVIF format for superior compression with proper browser fallbacks.

Utilities
Quick take
Typical fix time 20 min
  • AVIF offers 50% better compression than JPEG
  • Even better than WebP for photographic images
  • Use picture element with WebP and JPEG fallbacks
  • Browser support: Chrome, Firefox, Safari 16+, Edge
Why it matters: AVIF provides the best compression available—50% smaller than JPEG and 20% smaller than WebP—dramatically reducing bandwidth and improving load times.

Rule Details

AVIF is the most efficient image format available, offering superior compression for modern browsers.

Code Example

<picture>
  <!-- AVIF for modern browsers -->
  <source
    type="image/avif"
    srcset="
      image-400.avif 400w,
      image-800.avif 800w,
      image-1200.avif 1200w
    "
    sizes="(max-width: 600px) 100vw, 50vw"
  >
 
  <!-- WebP fallback -->
  <source
    type="image/webp"
    srcset="
      image-400.webp 400w,
      image-800.webp 800w,
      image-1200.webp 1200w
    "
    sizes="(max-width: 600px) 100vw, 50vw"
  >
 
  <!-- JPEG fallback for older browsers -->
  <img
    src="image-800.jpg"
    srcset="
      image-400.jpg 400w,
      image-800.jpg 800w,
      image-1200.jpg 1200w
    "
    sizes="(max-width: 600px) 100vw, 50vw"
    alt="Product image"
    width="800"
    height="600"
    loading="lazy"
  >
</picture>

Why It Matters

AVIF provides the best compression available—50% smaller than JPEG and 20% smaller than WebP—dramatically reducing bandwidth and improving load times.

Format Comparison

FormatCompressionBrowser SupportBest For
AVIFExcellent (best)93%+Photos, complex images
WebPVery good97%+General use
JPEGGood100%Fallback
PNGModerate100%Transparency, screenshots

Generating AVIF Images

# Using Sharp (Node.js)
npx sharp-cli input.jpg -o output.avif
 
# Using ImageMagick 7+
magick input.jpg output.avif
 
# Using avifenc (libavif)
avifenc input.png output.avif --min 20 --max 30
// Sharp programmatic conversion
const sharp = require('sharp')
 
async function convertToAvif(input, output) {
  await sharp(input)
    .avif({
      quality: 60, // AVIF quality (lower = smaller, 60 is good balance)
      effort: 4    // Compression effort (0-9, higher = slower but smaller)
    })
    .toFile(output)
}

Build Tool Integration

// webpack.config.js with image-minimizer-webpack-plugin
const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin')
 
module.exports = {
  optimization: {
    minimizer: [
      new ImageMinimizerPlugin({
        minimizer: {
          implementation: ImageMinimizerPlugin.sharpMinify,
          options: {
            encodeOptions: {
              avif: { quality: 60 },
              webp: { quality: 75 }
            }
          }
        },
        generator: [
          {
            preset: 'avif',
            implementation: ImageMinimizerPlugin.sharpGenerate,
            options: {
              encodeOptions: { avif: { quality: 60 } }
            }
          }
        ]
      })
    ]
  }
}

Next.js Configuration

// next.config.js
module.exports = {
  images: {
    formats: ['image/avif', 'image/webp'],
    // Next.js automatically serves AVIF when supported
  }
}

React Component with Format Negotiation

interface ModernImageProps {
  src: string
  alt: string
  width: number
  height: number
  sizes?: string
}
 
function ModernImage({ src, alt, width, height, sizes = '100vw' }: ModernImageProps) {
  const basePath = src.replace(/\.[^/.]+$/, '') // Remove extension
 
  return (
    <picture>
      <source
        type="image/avif"
        srcSet={`${basePath}.avif`}
      />
      <source
        type="image/webp"
        srcSet={`${basePath}.webp`}
      />
      <img
        src={`${basePath}.jpg`}
        alt={alt}
        width={width}
        height={height}
        loading="lazy"
        decoding="async"
      />
    </picture>
  )
}

CDN Auto-Format Conversion

<!-- Cloudinary auto format -->
<img src="https://res.cloudinary.com/demo/image/upload/f_auto,q_auto/sample.jpg">
<!-- Serves AVIF to supported browsers automatically -->
 
<!-- Imgix auto format -->
<img src="https://example.imgix.net/image.jpg?auto=format">
 
<!-- Cloudflare Polish (automatic) -->
<!-- Enable in dashboard - serves best format automatically -->

Quality Guidelines

Use CaseAVIF QualityEquivalent JPEG
Hero/large images50-6080-85
Product photos60-7085-90
Thumbnails40-5075-80
Icons/logosUse SVG or PNG instead

Support Notes

  • Image format and delivery behavior can vary by browser, CDN, and device characteristics, so verify the final bytes and rendered output on the supported browser matrix.
  • Add a fallback note when a modern format or loading behavior is not available for every required target browser.

Verification

  1. Check browser DevTools Network tab—verify AVIF is served
  2. Compare file sizes: AVIF vs WebP vs JPEG
  3. Verify fallback works in Safari < 16 or older browsers
  4. Check visual quality at different compression levels
  5. Test encoding time for build process impact
Encoding Time

AVIF encoding is slower than JPEG/WebP. Pre-generate AVIF images at build time rather than on-the-fly for large image sets.

Use with AI

Copy these prompts to use with your AI assistant, or install the MCP server to use directly from Claude, Cursor, or Windsurf.

Check

Verify implementation

Check if the website supports AVIF format for even better compression than WebP.

Fix

Auto-fix issues

Implement AVIF support with proper fallbacks for browsers that don't support it.

Explain

Learn more

Explain how AVIF provides 50% better compression than JPEG with superior quality.

Review

Code review

Review image assets, markup, and delivery configuration related to Use AVIF format for modern browsers. Flag exact files or components where format choice, sizing, or loading behavior violates the rule, and describe how to confirm the fix in DevTools.

Sources

References used to support the guidance in this rule.

Further Reading

Tools and supplementary material for exploring the topic in more depth.

Squoosh
squoosh.appTool

Rules that often go hand-in-hand with this one.

Use WebP format with fallbacks

Images are served in WebP format with fallbacks for older browsers.

Images
Use modern image formats (WebP, AVIF)

Images are served in modern formats (WebP or AVIF) instead of legacy JPEG/PNG where browser support allows, reducing file size without visible quality loss.

Images
Use <picture> with an <img> fallback

Every <picture> element contains a required <img> fallback as its last child, ensuring images display in all browsers including those that don't support <picture>.

Images
Use progressive JPEG encoding

JPEG images use progressive format for better perceived loading performance.

Images

Was this rule helpful?

Your feedback helps improve rule quality. This stays internal for now.

Loading feedback...
0 / 385