Image Formats Compared
Choosing the right image format is a real performance decision. Each format trades off compression, quality, transparency, and animation support differently—here's what each one is actually good at, and when to reach for it.
JPEG — Photos, Lossy
Best for: photographs, complex images with many colors and gradients.
Weak at: flat-color graphics, text, and logos — compression artifacts show up as blotchy noise around sharp edges.
No transparency and no animation.
PNG — Transparency, Lossless
Best for: logos, icons, screenshots, and graphics that need transparency.
Weak at: photographs — file sizes are much larger than equivalent JPEGs.
Transparency: yes (full alpha channel). Animation: no (use APNG or GIF instead).
GIF — Legacy Animation
GIF is an older format limited to 256 colors. It's still widely supported for simple looping animations, although modern formats are usually much smaller and better quality.
Best for: simple looping animations.
Weak at: photographs because of the 256-color limitation.
Transparency: yes, but only 1-bit transparency.
WebP — Modern, Smaller
WebP was designed to replace JPEG, PNG, and GIF with a single modern format. It supports both lossy and lossless compression, transparency, and animation while usually producing files 25–35% smaller than older formats.
Best for: almost everything—photos, graphics, and animations.
Watch out for: very old browsers. For maximum compatibility you can use a <picture> fallback.
AVIF — Newest, Best Compression
AVIF (AV1 Image File Format) often produces the smallest file sizes of all modern image formats while maintaining excellent visual quality. It also supports transparency and HDR.
Best for: maximum compression on modern browsers.
Watch out for: slower encoding and slightly newer browser support than WebP.
SVG — Vector
Best for: logos, icons, illustrations, and diagrams.
Weak at: photographs because vector graphics aren't designed for photographic detail.
SVG can be styled and animated with CSS and JavaScript and remains perfectly sharp on any display.
Comparison Table
Format | Compression | Transparency | Animation | Best for |
|---|---|---|---|---|
JPEG | Lossy | No | No | Photographs |
PNG | Lossless | Full alpha | No | Logos, screenshots, graphics |
GIF | Lossless (256 colors) | 1-bit only | Yes | Simple animations |
WebP | Lossy or Lossless | Full alpha | Yes | General purpose |
AVIF | Lossy or Lossless | Full alpha | Yes | Maximum compression |
SVG | Vector | Full alpha | Via CSS/SMIL | Logos and icons |
Choosing a Format in Practice
picture-fallback.html
<picture>
<source srcset="/media/hero.avif" type="image/avif">
<source srcset="/media/hero.webp" type="image/webp">
<img
src="/media/hero.jpg"
alt="Team collaborating around a laptop"
width="1200"
height="600"
>
</picture><picture> with multiple <source> elements lets the browser choose the best format it supports—typically AVIF first, WebP second, and JPEG or PNG as the final fallback.srcset, sizes, lazy loading, and responsive images has an even bigger impact on real-world performance.