GIF vs MP4 vs WebP (and AVIF): which format for a short looping animation?

A short loop for a website, a bug report, a README or a chat: which format should it be? It depends on where it's going more than on the picture.

Side by side

GIFAnimated WebPMP4 (H.264)Animated AVIF
Typical size for the same clipLargest (baseline)~25 to 50% of the GIF~3 to 10% of the GIFSmallest, often below MP4
Colours256 per frameFull colourFull colourFull colour, HDR possible
TransparencyOn/off only (hard edges)SmoothNo (in H.264 MP4)Smooth
SoundNoNoYes (mute it for a loop)No
Works as an <img>EverywhereAll current browsersNo, needs <video>Current browsers
Accepted by upload formsAlmost alwaysOftenWhere video is allowedSometimes

Sizes vary with content: flat screen recordings narrow the gap, camera footage widens it.

Why the gap is so big

GIF compresses each frame on its own, a bit like zipping a stack of bitmaps. Video formats predict each frame from the previous one and only store the difference, and they throw away detail your eye won't miss (see lossless vs lossy compression). WebP and AVIF borrow those video tricks but package the result as an image, which is why they sit in between.

Which to use where

Converting between them with ffmpeg

GIF to MP4 (the scale keeps the dimensions even, which H.264 needs):

ffmpeg -i input.gif -movflags +faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" output.mp4

Video to animated WebP:

ffmpeg -i input.mp4 -vf "fps=12,scale=480:-2" -c:v libwebp -lossless 0 -q:v 70 -loop 0 -an output.webp

Video to a good GIF uses a two-step palette; the GIF size calculator writes those commands for your width, frame rate and colours, and why is my GIF so big explains each setting.

Questions

Is MP4 smaller than GIF?

Almost always, often 10 to 30 times smaller for the same clip, because video only stores what changes between frames. Flat screen recordings narrow the gap.

Is animated WebP better than GIF?

For size and colour, yes: it's full colour with smooth transparency and usually a quarter to half the size. GIF still wins on compatibility, especially in email and some upload forms.

Can I use an MP4 instead of a GIF on a web page?

Yes. Use a video tag with autoplay, muted, loop and playsinline. It behaves like a GIF but loads far faster.

Does GIF support more than 256 colours?

Not in practice. Each frame has a palette of at most 256 colours, which is why photos and gradients look blotchy or dotted in GIFs.

How do I convert a GIF to MP4?

With ffmpeg: ffmpeg -i input.gif -movflags +faststart -pix_fmt yuv420p -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" output.mp4. It runs on your own computer.

Published .

Try it

Related guides

Newest guides