Animation formats compared: GIF, APNG, animated WebP, AVIF and short video loops
Why a 5-second animated GIF can weigh 12 MB while the same animation in WebM, MP4, or animated WebP weighs 350 KB—and how to test multi-frame image decoders in your upload pipeline.
1. Why 1989 GIF89a struggles with modern animations
The Graphics Interchange Format (GIF89a) was designed in 1987–1989 for CompuServe dial-up modems. It compresses each frame using 1-dimensional Lempel-Ziv-Welch (LZW) dictionary coding and restricts each frame's local or global palette to at most 256 indexed colors (8-bit palette) with 1-bit binary transparency (a pixel is either 100% opaque or 100% transparent—no smooth anti-aliased alpha edges). Because LZW has no inter-frame motion compensation and cannot represent smooth 24-bit photographic gradients without heavy dithering noise, animated GIFs of screen recordings or video clips explode in byte size.
2. Technical comparison of the 5 web animation formats
| Format | Color depth & Alpha | Compression method | HTML tag used | Sample fixture on this site |
|---|---|---|---|---|
| GIF (.gif) | 8-bit palette (256 colors), 1-bit transparency | Per-frame LZW | <img> | sample-animated-loop.gif |
| APNG (.apng / .png) | 24-bit RGB + 8-bit smooth alpha (32-bit RGBA) | Lossless DEFLATE + delta frames | <img> | sample.apng |
| Animated WebP (.webp) | 24-bit RGB/YUV + 8-bit alpha | Lossy VP8 or Lossless VP8L + ANMF chunks | <img> | sample-animated.webp |
| AVIF Sequence (.avif) | 8/10/12-bit YUV/RGB + alpha | AV1 inter-frame motion prediction | <img> | sample.avif |
| MP4 / WebM Loop | 8/10-bit YUV (4:2:0 / 4:4:4) | H.264 / VP9 / AV1 inter-frame coding | <video autoplay loop muted playsinline> | sample-video-640x360.mp4 |
3. Testing multi-frame uploads and thumbnail extractors
- Detecting animated vs. static PNGs and WebPs: A user can rename
sample.apngtoavatar.png, or upload an animated.webpwhere your backend expects a single static frame. To detect APNG, scan the PNG chunk stream prior to the firstIDATchunk for the 4-byte ASCII chunk typeacTL(Animation Control). To detect animated WebP, check whether bytes 12–15 areVP8X(Extended WebP) and bit 1 (0x02) of the flags byte at offset 20 is set. - Avoiding memory exhaustion ("GIF bombs"): A 200 KB animated GIF with 2,000 frames at
1920×1080expands to1920 × 1080 × 4 × 2000 ≈ 16.5 GBof uncompressed RGBA memory if an image resizer callscoalesce()on all frames at once. Always cap maximum frame count and total pixel area (width × height × frames) before decoding animations.