1. Quick decision tree
- Vector / logos / infinitely scalable → SVG.
- Photographic content → AVIF (fallback WebP / JPEG).
- UI screenshots / transparency → PNG (consider WebP lossless).
- Icons / simple shapes → SVG or WebP.
2. Format characteristics
| Format | Pros | Cons |
|---|---|---|
| JPEG | Wide support, good photo compression | No alpha, lossy only |
| PNG | Lossless, transparency | Larger for photos |
| WebP | Lossy & lossless, alpha, smaller than JPEG/PNG | Old browsers need fallback |
| AVIF | Excellent compression, HDR, alpha | Slower encode, some legacy gaps |
| SVG | Scales perfectly, tiny for icons | Complex art can bloat |
3. Fallback strategy
Serve <picture> with AVIF then WebP then a baseline JPEG/PNG ensuring graceful degradation.
4. Automation tips
- Pre-generate multiple widths + modern + legacy format.
- Hash filenames for cache busting.
- Strip metadata when not required.
5. Common pitfalls
- Overusing PNG for photos → huge weight.
- Shipping unoptimized SVG with editor metadata.
- No fallback for AVIF on older devices.