Prompt
How do I switch my site images to AVIF?
Latest observation
Switching site images to AVIF usually means changing your image pipeline so browsers get AVIF where supported, with a fallback to WebP/JPEG/PNG for older browsers.
Best approach
1) Keep your original images
Don’t replace your source files with AVIF only. Keep originals like:
.psd,.ai,.png,.jpg,.webp- generate AVIF derivatives at build time or upload time
2) Generate AVIF versions
Use an image tool or build step.
Examples:
Using sharp in Node.js
import sharp from "sharp";
await sharp("input.jpg")
.avif({ quality: 50 })
.toFile("output.avif");
Using ImageMagick
magick input.jpg -quality 50 output.avif
Using cwebp/avifenc or build tools
If you already use a bundler, plugins often handle this automatically.
3) Serve AVIF with fallback
Use <picture> so browsers can choose the best format:
<picture>
<source srcset="image.avif" type="image/avif">
<source srcset="image.webp" type="image/webp">
<img src="image.jpg" alt="Description">
</picture>
If AVIF is supported, the browser uses it; otherwise it falls back to WebP or JPEG.
4) For CSS background images
Use image-set():
.hero {
background-image: image-set(
url("hero.avif") type("image/avif"),
url("hero.webp") type("image/webp"),
url("hero.jpg") type("image/jpeg")
);
}
You may still need a fallback rule for browsers that don’t support image-set() well.
5) Use responsive sizes
AVIF helps most when paired with responsive images:
<picture>
<source
type="image/avif"
srcset="img-480.avif 480w, img-960.avif 960w, img-1440.avif 1440w"
sizes="(max-width: 768px) 100vw, 50vw">
<img
src="img-960.jpg"
srcset="img-480.jpg 480w, img-960.jpg 960w, img-1440.jpg 1440w"
sizes="(max-width: 768px) 100vw, 50vw"
alt="Description">
</picture>
Important considerations
Browser support
AVIF is supported in modern browsers, but not all older ones. That’s why fallbacks matter.
Quality setting
AVIF is usually smaller than JPEG/WebP at similar visual quality, but encoding can be slower. A common starting point is:
- photos: quality around 45–60
- graphics/screenshots: test carefully, sometimes higher quality is needed
Transparency
AVIF supports transparency, so it can replace PNG in many cases.
Animation
AVIF can support animation, but support/performance can vary. Test before using it for animated assets.
If you use a CMS or framework
Many platforms can auto-generate AVIF:
- Next.js: use
next/imagewith an image loader or built-in optimization depending on setup - Astro / Vite / Nuxt / Gatsby: often via plugins
- WordPress: plugins or server-side image optimization services
- Cloudinary / Imgix / ImageKit: can serve AVIF automatically based on browser support
Simple migration plan
- Inventory your image types: hero images, thumbnails, icons, backgrounds.
- Generate AVIF for photo-like images first.
- Add
<picture>or equivalent fallback handling. - Test across Chrome, Safari, Firefox, Edge.
- Measure page weight and visual quality.
- Gradually expand to the rest of the site.
If you tell me what your site uses—plain HTML, WordPress, Next.js, Shopify, etc.—I can give you the exact steps and code for that stack.