HTML

Introduction to Web and HTML

How the Web Works What is HTML Why Learn HTML

Video Formats (MP4, WebM, Ogg)

Video Formats in HTML

When embedding videos in your HTML documents, it's essential to consider various video formats to ensure compatibility across different browsers and devices. The most common video formats used in web development are MP4, WebM, and Ogg.

MP4 (H.264)

MP4, also known as H.264, is a widely supported video format. It is compatible with most modern browsers, including Chrome, Firefox, Safari, and Internet Explorer. MP4 videos offer excellent video quality and compression, making them a popular choice for web video content.

<video controls>
  <source src="video.mp4" type="video/mp4">
  Your browser does not support the video element.
</video>

WebM

WebM is an open and royalty-free video format developed by Google. It offers efficient video compression and is supported by many browsers, including Chrome, Firefox, and Opera. It's a great choice for web videos when you want to reach a broad audience.

<video controls>
  <source src="video.webm" type="video/webm">
  Your browser does not support the video element.
</video>

Ogg (Ogg Theora)

Ogg, specifically Ogg Theora, is an open and royalty-free video format suitable for web video content. It is supported by some browsers, including Firefox. While not as widely supported as MP4 and WebM, Ogg remains an option for providing video content to users who prefer open formats.

<video controls>
  <source src="video.ogv" type="video/ogg">
  Your browser does not support the video element.
</video>

Providing Multiple Formats

To ensure compatibility with a broader range of browsers, it's a good practice to provide video content in multiple formats. You can do this by including multiple <source> elements within your <video> element.

<video controls>
  <source src="video.mp4" type="video/mp4">
  <source src="video.webm" type="video/webm">
  <source src="video.ogv" type="video/ogg">
  Your browser does not support the video element.
</video>

By offering multiple formats, you increase the likelihood that users can access your video content without compatibility issues.

Video Conversion

You can use various video conversion tools and software to create videos in these different formats. Popular video editors and converters often include options to export videos in MP4, WebM, and Ogg formats.

In summary, understanding the common video formats, such as MP4, WebM, and Ogg, is crucial when embedding videos in your HTML documents. Providing multiple formats ensures that your video content is accessible to a wide audience, regardless of the browser or device they use.