Master AVIF compression settings. Reference for quality, speed, chroma, bit depth, and lossless parameters with practical code examples.
Dialing In avifenc and sharp
AVIF exposes the full AV1 encoder surface, so the right settings change the file size of one image by 3–5x. This reference defines each parameter, its exact range, and the value to pick per use case.
The format itself — savings, features, and tradeoffs — is covered in the AVIF format overview. For the mode-choice question, read Lossy vs Lossless Compression. For the wider performance picture, see AVIF Optimization.
Read the quality scale correctly
AVIF quality numbers do not match JPEG or WebP numbers. A photo at AVIF quality 60 looks roughly like JPEG quality 85.
Two scales exist in the wild, and confusing them ruins results:
- Quality 0–100 (
-q/--qcolorin avifenc,qualityin sharp) — higher is better, 100 is lossless. - Quantizer 0–63 (the legacy
--min/--maxpair) — lower is better, 0 is lossless.
Since libavif 1.2.0, --qcolor is the recommended flag and --min/--max are deprecated. Use the 0–100 quality scale in new pipelines. If you import a JPEG-era habit of "quality 82 to be safe," AVIF files come out oversized and you wrongly conclude AVIF is not smaller. The web target is quality 55–65, not 80+.
Quality: -q / --qcolor (0–100)
-q (alias --qcolor) is the single highest-impact parameter. It sets color-plane quality from 0 (worst) to 100 (lossless).
| Quality | Use |
|---|---|
| 75–85 | Hero and above-the-fold photography |
| 60–72 | Production sweet spot, most photos |
| 50–60 | Article body and product imagery |
| 35–50 | Thumbnails and below-the-fold content |
# Modern quality form (libavif 1.2.0+)
avifenc -q 60 input.jpg output.avif
# Legacy quantizer form (still works, lower = better)
avifenc --min 24 --max 36 input.jpg output.avif
The two forms above produce comparable output; -q 60 is roughly --min 24 --max 36. Prefer the quality form going forward.
Speed: -s / --speed (0–10)
-s controls encoder effort from 0 (slowest, smallest) to 10 (fastest, largest). The avifenc default is 6. Lower speed means a smaller file for identical quality.
| Speed | Time cost | Where to use |
|---|---|---|
| 0–2 | Very slow | Hero assets encoded once |
| 4 | Moderate | Build-pipeline default |
| 6 | Default | On-the-fly conversion |
| 8–10 | Fast | Live thumbnail generation |
Encoding happens once; serving happens forever. A 1200x800 photo can take 5–20 seconds at speed 0–2, so budget for it on large batches. Speed 4 is the sane build default; drop to 0–2 only for heroes.
avifenc -s 4 -q 60 input.jpg output.avif
Chroma subsampling: -y / --yuv
avifenc accepts 444, 422, 420, and 400 (greyscale); the default is auto. Subsampling discards color resolution the eye barely tracks.
-y 420— quarter-resolution chroma, smallest files. Correct for photographs and natural images.-y 444— full-resolution chroma. Required for text, screenshots, charts, logos, and saturated hard edges, where 420 causes color bleed.-y 422— a middle ground; rarely the best pick on still images.
# Photograph
avifenc -y 420 -q 60 photo.jpg photo.avif
# Screenshot with coloured text
avifenc -y 444 -q 70 screenshot.png screenshot.avif
Note: sharp defaults to 4:4:4, so set chromaSubsampling: "4:2:0" explicitly for photos or files come out larger than necessary.
Bit depth: -d / --depth (8, 10, 12)
AVIF encodes 8, 10, or 12 bits per channel — a capability WebP and baseline JPEG lack. Default is 8.
-d 8— standard dynamic range, correct for almost all web content.-d 10— HDR and wide-gamut content; pair with--cicpcolor signalling, for example BT.2020 PQ.-d 12— mastering and archival HDR; overkill for delivery.
# 10-bit HDR, BT.2020 + PQ
avifenc -d 10 --cicp 9/16/9 hdr.png hdr.avif
Encoding HDR sources as 8-bit AVIF throws away the tonal range that justified AVIF over JPEG. Keep the depth when the source is HDR.
Transparency: --qalpha
The alpha plane is encoded separately on its own 0–100 quality scale. Tune it apart from color.
- Keep
--qalpha 100(lossless alpha) when transparency edges must stay crisp — logos, icons, UI chrome. - Lower to
--qalpha 80–90for soft alpha such as shadows or feathered cut-outs; bytes drop with no visible change.
avifenc -q 55 --qalpha 100 product.png product.avif
Lossless: -l / --lossless
-l switches every default to bit-exact reconstruction and warns when a setting would break that guarantee. It internally uses -y 444 and ignores the lossy quality flags.
avifenc -l logo.png logo.avif
Lossless AVIF competes with PNG and lossless WebP and sometimes wins, but PNG stays the safe choice for pixel-exact line art — measure both. Expect files far larger than lossy AVIF, so reserve lossless for content where any loss is unacceptable. See PNG format overview for the comparison baseline.
Tiling for large images
Tiling splits an image into independently coded regions, which speeds multi-threaded encode and decode at a tiny size cost. avifenc enables --autotiling by default, so most users need no flags. For manual control, --tilerowslog2 and --tilecolslog2 accept 0–6.
For hero photos above ~1500px, tiling cuts decode time on multi-core clients with negligible size impact. Leave it off for small images, where the overhead outweighs the gain.
Codec choice: -c / --codec
avifenc can drive three AV1 encoders. The choice trades speed against compression.
-c aom— reference encoder, smallest files, slowest.-c rav1e— Rust encoder, faster, slightly larger files.-c svt— SVT-AV1, fastest, good for high-throughput batches.
For a one-time hero export use aom; for a fast CI batch consider svt.
Presets by use case
Each row is a tested starting point; spot-check output against the source before shipping a library.
| Use case | Mode | avifenc command |
|---|---|---|
| Web photo (body) | Lossy | -s 4 -q 58 -y 420 |
| Hero / above-the-fold | Lossy | -s 2 -q 78 -y 420 |
| Thumbnail | Lossy | -s 6 -q 45 -y 420 |
| Screenshot with text | Lossy | -s 4 -q 70 -y 444 |
| Chart or diagram | Lossy | -s 4 -q 75 -y 444 |
| Product on white (alpha) | Lossy | -s 4 -q 58 --qalpha 100 |
| Logo / line art | Lossless | -l (compare with PNG) |
| HDR photography | Lossy | -s 2 -d 10 -q 70 --cicp 9/16/9 |
sharp (Node.js) example
sharp is the production choice for build pipelines, using libheif/aom under the hood. Its .avif() options differ slightly from avifenc.
import sharp from "sharp";
await sharp("source.jpg")
.resize({ width: 1200, withoutEnlargement: true })
.avif({
quality: 58, // 1–100, default 50; AVIF scale, not JPEG
effort: 4, // 0 (fastest) to 9 (slowest); default 4
chromaSubsampling: "4:2:0", // sharp defaults to 4:4:4
lossless: false,
bitdepth: 8, // 8, 10, or 12
})
.toFile("output.avif");
Two sharp-specific gotchas:
effortis 0–9, not avifenc's 0–10, and higher means slower/smaller — the inverse direction of avifenc's--speed.chromaSubsamplingdefaults to4:4:4, so photos need an explicit"4:2:0"to compress fully.
For text or line art, set chromaSubsampling: "4:4:4" and raise quality to 70+.
Inspecting the result
Verify what you encoded. avifdec --info dumps the structure — dimensions, bit depth, chroma format, and alpha presence:
avifdec --info output.avif
For a numeric quality check against the source, run an SSIM or DSSIM comparison; for a visual pixel diff, Squoosh loads two files side by side. Tune until the smallest file shows no visible loss at real viewing size.
FAQ
What AVIF quality should I use for web photos?
Use quality 55–65 on the 0–100 scale. That matches roughly JPEG quality 85 at far smaller size.
Is lower or higher better in avifenc?
On -q higher is better (100 = lossless); on the legacy --min/--max quantizer lower is better. Prefer -q.
Why is my AVIF bigger than expected from sharp?
sharp defaults chroma to 4:4:4. Set chromaSubsampling: "4:2:0" for photographic content.
Does lower --speed make smaller files?
Yes. Speed 0–2 produces the smallest files but is far slower; speed 4 is a good build default.
When should I keep 4:4:4 chroma?
Keep 4:4:4 for text, screenshots, charts, and saturated hard edges, where 4:2:0 introduces color fringing.
Where to go from here
- AVIF Optimization — the bigger delivery and performance picture
- Lossy vs Lossless Compression — picking the right mode per image
- AVIF Browser Support — what ships safely today
- Core Web Vitals and Images — how these bytes affect LCP
- Convert a library now: JPG to AVIF, PNG to AVIF