WebM vs MP4 — Which Format Is Best for the Web?
Published · Updated
MP4 with H.264 is a practical starting point for many website videos. A VP9 WebM can be useful as an additional source if it gives a better size-and-quality result for your footage. Compare the actual exports and test your target devices before choosing either.
Check the codec as well as the extension
WebM and MP4 are containers. The codec determines how their video tracks are compressed. Two files ending in .mp4 can use different codecs and have different playback support. MDN’s container guide explains the distinction.
| File | Example codec | What to check |
|---|---|---|
| MP4 | H.264 / AVC | Playback on your target devices; progressive loading |
| WebM | VP9 | File size and quality compared with your MP4 |
| MP4 or WebM | AV1 | Decoder availability, playback cost, and encoding time |
| MP4 | HEVC / H.265 | Platform-specific playback support |
Choose using a representative clip
- Export the same segment from the same master, with matching dimensions and frame rate.
- Adjust each encoder until text, motion, and gradients meet your needs. Identical quality-slider numbers across encoders are not equivalent settings.
- Compare the resulting sizes and record the export settings.
- Play each result on your supported phones and computers, including lower-powered devices if they matter to your audience.
There is no fixed percentage saving for changing formats. Footage, encoder settings, audio, and acceptable image quality all affect the result. Keep the smaller acceptable version, even when it is not the format you expected to win.
Provide two sources when both are useful
<video controls playsinline preload="metadata"
poster="/media/demo-poster.webp" width="1280" height="720">
<source src="/media/demo.webm" type="video/webm" />
<source src="/media/demo.mp4" type="video/mp4" />
</video>
This example prefers WebM. The browser chooses a usable source in the listed order; it does not compare their file sizes and choose the smaller one. Put MP4 first if that is the version you prefer. A single tested MP4 is also a reasonable choice when maintaining two versions adds no useful benefit.
Why a browser-name checklist is insufficient
Codec support can depend on the operating system, hardware, profile, and bit depth as well as the browser version. In particular, HEVC is not limited to Safari, and AV1 availability cannot be inferred from a Safari version number alone. Check the platform notes in the MDN codec guide, then test the encoded file.
For a capability check, canPlayType() can help narrow the problem, but a positive answer does not prove the deployed file will play. The playback troubleshooting guide covers the file, server, and autoplay checks.
Once you have chosen your formats, follow the export guide for posters, player markup, and deployment checks. Use compression settings to reduce transfer size without making a screen recording unreadable.