[ BLOG ]For Frontend Engineers · 3 min read

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.

FileExample codecWhat to check
MP4H.264 / AVCPlayback on your target devices; progressive loading
WebMVP9File size and quality compared with your MP4
MP4 or WebMAV1Decoder availability, playback cost, and encoding time
MP4HEVC / H.265Platform-specific playback support

Choose using a representative clip

  1. Export the same segment from the same master, with matching dimensions and frame rate.
  2. Adjust each encoder until text, motion, and gradients meet your needs. Identical quality-slider numbers across encoders are not equivalent settings.
  3. Compare the resulting sizes and record the export settings.
  4. 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.