HTML Video

HTML

← Prev

In this tutorial we will learn about the video tag to work with video files in HTML.

What are video tags in HTML?

The video tag is a HTML5 element and it is used to embed video in the web page.

Example

In the following example we are creating a video element.

<video width="200" controls src="path/to/video-file.mp4">
  Your browser does not support the HTML video tag.
</video>

Another way we can do this is by using the source tag and including multiple files.

<video width="200" controls>
  <source src="path/to/video-file.mp4" type="video/mp4">
  <source src="path/to/video-file.ogg" type="video/ogg">
  <source src="path/to/video-file.webm" type="video/webm">
  Your browser does not support the HTML video tag.
</video>

Note! In the above example the text Your browser does not support the HTML video tag. will be displayed if the browser does not supports video tag.

Supported video format

Following are the supported video format.

FileExtensionMIME Type
MP4.mp4video/mp4
OGG.oggvideo/ogg
WebM.webmvideo/webm

You can use the Find Fileinfo of this website to find the MIME type of the video files.

The source tag

We can also use the source tag to include one or more video files.

For this we set the src attribute to the video file URL and type attribute to the MIME type of the video file.

In the following exmaple we are using 3 different file types.

<source src="/video/video-file.mp4" type="video/mp4">
<source src="/video/video-file.ogg" type="video/ogg">
<source src="/video/video-file.webm" type="video/webm">

If we are using the source element then we can skip the src attribute in the opening video tag.

Attributes for the video tag

Following are the attributes that we can add to the video tag.

AttributeValueDescription
controlscontrolsIf present will allow the user to control the video playback by providing seek, volume and pause/resume controls.
preloadnone
auto
metadata
This tells the browser about what the author thinks will provide a better user experience. It is an enumerated attribute and can take the following values.
none - Indicating not to preload the video.
auto - Download the whole video file even if the user is not going to use it.
metadata - Fetch only the metadata of the video like length.
autoplayautoplayIf present will start playing the video as soon as it can do so.
looploopIf present will start playing the video all over again.
mutedmutedIf specified will mute the video.
srcurlThis specifies the url of the video file.
widthinteger valueThis defines the width of the display area.
heightinteger valueThis defines the height of the display area.
posterurlIf specified will show the poster for the video until the user plays the video.
← Prev