HTML Video

What is HTML Video tag

The HTML <video> tag is used to embed video files on a web page. It can be used to play a variety of video formats such as MP4, OGG, and WEBM. The <video> tag supports various attributes, such as src (to specify the source of the video file), controls (to display the default video player controls), and loop (to loop the video file continuously). Additionally, it has some attributes like width and height that are used to set the size of the video, poster to set an image as a placeholder before the video starts playing. An example of an <video> tag is:

<video src="example.mp4" controls width="320" height="240"></video>

This will embed a video file called “example.mp4” with a width of 320 pixels and a height of 240 pixels, and display the default video player controls on the web page.

Currently, there are three video formats supported for HTML video tag:

  1. mp4
  2. webM
  3. ogg

Video Tag Example

<!DOCTYPE>
<html>

<body>
    <video controls>
        <source src="movie.mp4" type="video/mp4">
        Your browser does not support the html video tag.
    </video>
    <p>
        Video courtesy of
        <a href="https://www.pexels.com/" target="_blank">Pexels</a>.
    </p>
</body>

</html>

Output

Video

Here is a table that compares the HTML <audio> tag and the <video> tag:

Feature<audio> Tag<video> Tag
PurposeEmbed audio filesEmbed video files
Supported file formatsMP3, OGG, WAVMP4, OGG, WEBM
Default player controlsAvailableAvailable
AutoplaySupportedSupported
LoopSupportedSupported
Width and HeightNot supportedSupported
Poster ImageNot supportedSupported

It is worth mentioning that <audio> and <video> tags both support the src, controls, autoplay, loop, muted, preload attributes, and some events like onplay, onpause, onended and onvolumechange .

It’s also worth noting that the <audio> tag is used for audio only, while the <video> tag can include both audio and video.

Video Tag Attributes

Let’s see the list of HTML 5 video tag attributes.

AttributeDescription
controlsIt defines the video controls which is displayed with play/pause buttons.
heightIt is used to set the height of the video player.
widthIt is used to set the width of the video player.
—–———————–
autoplayIt specifies that the video will start playing as soon as it is ready.
loopIt specifies that the video file will start over again, every time when it is completed.
mutedIt is used to mute the video output.
preloadIt specifies the author view to upload video file when the page loads.
srcIt specifies the source URL of the video file.
HTML Video
  1. The HTML <video> tag is used to embed video files on a web page.
  2. The <video> tag supports various attributes, such as src (to specify the source of the video file), controls (to display the default video player controls), and loop (to loop the video file continuously).