Skip to main content

HTML Video

The HTML <video> element is used to show a video on a web page.

HTML Video Tags

TagDescription
<video>Defines a video or movie
<source>Defines multiple media resources for media elements, such as <video> and <audio >
<track>Defines text tracks in media players

The HTML <video> Element

To show a video in HTML, use the <video> element:

<video width="320" height="240" controls>  
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>

How it Works

The controls attribute adds video controls, like play, pause, and volume.

It is a good idea to always include width and height attributes. If height and width are not set, the page might flicker while the video loads.

The <source> element allows you to specify alternative video files which the browser may choose from. The browser will use the first recognized format.

The text between the <video> and </video> tags will only be displayed in browsers that do not support the <video> element.

Attributes of HTML Video Tag

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.
posterIt specifies the image which is displayed on the screen when the video is not played.
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> Autoplay

To start a video automatically, use the autoplay attribute:

<video width="320" height="240" autoplay>  
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
note

Chromium browsers do not allow autoplay in most cases. However, muted autoplay is always allowed.

Add muted after autoplay to let your video start playing automatically (but muted):

<video width="320" height="240" autoplay muted>  
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>

HTML Video Formats

There are three supported video formats: MP4, WebM, and Ogg. The browser support for the different formats is:

BrowserMP4WebMOgg
Edge✔️✔️✔️
Chrome✔️✔️✔️
Firefox✔️✔️✔️
Safari✔️✔️
Opera✔️✔️✔️

MIME Types for HTML Video format

The available MIME type HTML video tag is given below.

Video FormatMIME Type
mp4video/mp4
oggvideo/ogg
webMvideo/webM

`