What is <video> tag ?
<video> tag is an inline element used to embed video content into a web page.
<video> tag is used to add any videos, for example music video or news video, to our web pages.
What are the supported formats for <video> tag ?
Only three certain formats are supported by HTML5 <video> tag, listed below
1. mp4
2. ogg
3. webM
Note : All three formats are not supported in all browsers.
Simple <video> tag
Example :
<!DOCTYPE html>
<html>
<head>
<title>Video Tag</title>
</head>
<body>
<p>MP4 Format</p>
<video width="300" height="200" autoplay>
<source src="example1.mp4" type="video/mp4">
</video>
<p>Ogg Format</p>
<video width="300" height="200" autoplay>
<source src="example2.ogv" type="video/ogg">
</video>
<p>WebM Format</p>
<video width="300" height="200" autoplay>
<source src="example3.webm" type="video/webm">
</video>
</body>
</html>
<video> – Defines the start and end of <video> and </video> tags.
width, height – Defines the width and height of the video section.
If not set the webpage will flicker while loading the video file.
source – Defines the source location of the video file.
type – Defines the supported format type of the video file.
Output :

HTML beginners tutorial !!!
Click to Learn More about – HTML Tutorial for beginners
What are the attributes for <video> tag ?
Some of the attributes can be used with <video> tag listed below,
1. height and width
2. src
3. autoplay
4. controls
5. loop
6. muted
7. poster
8. preload
1. height and width
Defines the width and height of the video player.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Video Tag</title>
</head>
<body>
<p>MP4 Format</p>
<video width="300" height="200">
<source src="example1.mp4" type="video/mp4">
</video>
</body>
</html>
Output :

2. src
Defines the source URL of the video.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Video Tag</title>
</head>
<body>
<p>MP4 Format</p>
<video width="300" height="200">
<source src="example1.mp4" type="video/mp4">
</video>
</body>
</html>
Output :

3. autoplay
Defines the video will play immediately after it loads.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Video Tag</title>
</head>
<body>
<p>MP4 Format</p>
<video width="300" height="200" autoplay>
<source src="example1.mp4" type="video/mp4">
</video>
</body>
</html>
Output :

4. controls
Defines the controls to display with the video player.
This is a Boolean value( New attribute in HTML5).
The video control should include:
1. Play
2. Pause
3. Volume
4. Full-screen Mode
5. Seeking
6. Captions/Subtitles(if available)
7. Track(if available)
Example :
<!DOCTYPE html>
<html>
<head>
<title>Video Tag</title>
</head>
<body>
<p>MP4 Format</p>
<video controls width="300" height="200">
<source src="example1.mp4" type="video/mp4">
</video>
</body>
</html>
Output :

5. loop
Defines the video should continuously repeat.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Video Tag</title>
<script>
var id = document.getElementById("egVideo");
function enableLoop() {
id.loop = true;
id.load();
}
</script>
</head>
<body>
<p>MP4 Format</p>
<video controls id="egVideo" width="300" height="200">
<source src="example1.mp4" type="video/mp4">
</video><br/>
<button onclick="enableLoop()" type="button"><b>Enable loop</b></button>
</body>
</html>
Output :

6. muted
Defines the audio output should be muted.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Video Tag</title>
<script>
var id = document.getElementById("egVideo");
function enableLoop() {
id.muted = true;
}
</script>
</head>
<body>
<p>MP4 Format</p>
<video controls id="egVideo" width="300" height="200">
<source src="example1.mp4" type="video/mp4">
</video><br/>
<button onclick="enableLoop()" type="button"><b>Enable Muted</b></button>
</body>
</html>
Output :

7. poster
Defines an image to be shown while the video is downloading, or first loads.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Video Tag</title>
<script>
var id = document.getElementById("egVideo");
function enableLoop() {
id.muted = true;
}
</script>
</head>
<body>
<p>MP4 Format</p>
<video controls id="egVideo" width="300" height="200" poster="https://secureservercdn.net/192.169.221.188/s30.e0b.myftpupload.com/wp-content/uploads/2020/10/html5-title-cc-1.png">
<source src="example1.mp4" type="video/mp4">
</video><br/>
</body>
</html>
Output :

8. preload
Defines how and when the video should load.
Example :
<!DOCTYPE html>
<html>
<head>
<title>Video Tag</title>
<script>
var id = document.getElementById("egVideo");
function enableLoop() {
id.muted = true;
}
</script>
</head>
<body>
<p>MP4 Format</p>
<video controls id="egVideo" width="300" height="200" preload="auto">
<source src="example1.mp4" type="video/mp4">
</video><br/>
</body>
</html>
Output :

<video> Tag Attributes
HTML <video>
tag support following specific attributes.
Sno | Attributes | Value | Description |
---|---|---|---|
1 | autoplay | autoplay | Attached video will play automatically when it loads. |
2 | controls | controls | Specifies that controls should display with the audio player such as play, stop, pause button. |
3 | height | pixels | Specifies the height, to display the video. |
4 | loop | loop | Specifies that video will automatically start over again, when reaching the end of the video. |
5 | muted | muted | Specifies that the audio will be initially silenced, when the video is played. |
6 | poster | URL | Specifies the image to be shown while the video is downloading or until user start to play video. |
7 | preload | none auto metadata | Specifies how the author thinks the video file should be loaded as per best user experience. |
8 | src | URL | Specifies the URL of video file. |
9 | width | pixels | Specifies the width, to display the video. |
Global Attributes
HTML <video>
tag support following global attributes.
Sno | Attributes | Value | Description |
---|---|---|---|
1 | id | unique_name | Declared unique id for an element. |
2 | class | class_name | Declared one or more classnames for an element. |
3 | style | styles | CSS inline styles specify an element. |
4 | title | title | Specify extra details of element contain, this will display as a “tooltip” for an elements. |
Event Attributes
HTML <video>
tag support following event attributes.
Sno | Attributes | Value | Description |
---|---|---|---|
1 | onfocus | script | element gets focus on object when script tobe run. |
2 | onblur | script | element lose the focus on object when scrip tobe run. |
3 | onabort | script | element gets aborted on object when script tobe run. |
4 | onchange | script | element gets anytime change on object when script tobe run. |
5 | onbeforeunload | script | element gets unloaded on object when scrip tobe run. |
6 | onclick | script | clicked on object when script tobe run. |
7 | ondblclick | script | double click on object when script tobe run. |
8 | onkeydown | script | key is pressed when script tobe run. |
9 | onkeypress | script | key is pressed over element then released when script tobe run. |
10 | onkeyup | script | key is released over element when script tobe run. |
11 | onmousedown | script | mouse button was pressed over an element when script tobe run. |
12 | onmouseout | script | mouse pointer release over an element when script tobe run. |
13 | onmousemove | script | run mouse pointer moved when script tobe run. |
14 | onmouseover | script | run mouse pointer move over when script tobe run. |
15 | onmouseup | script | mouse button is released when script tobe run. |
16 | onreset | script | form has been reset when script tobe run. |
17 | onselect | script | Select some content when script tobe run. |
18 | onsubmit | script | form has been submitted when script tobe run. |
19 | onload | script | object has load when script tobe run. |
20 | onchange | script | allow to change the object when script tobe run. |
21 | onunload | script | unload to the browser window when script tobe run. |
22 | ondrag | script | element being dragged when script tobe run. |
23 | ondragend | script | element being stop dragged when script tobe run. |
24 | ondragenter | script | element being go target dragged when script tobe run. |
25 | ondragleave | script | element being leave to target dragged when script tobe run. |
26 | ondragover | script | element being over to target dragged when script tobe run. |
27 | ondragstart | script | element being start dragged when script tobe run. |
28 | ondrop | script | element being dropped when script tobe run. |
29 | onerror | script | element error occurs when script tobe run. |
30 | onmessage | script | element message display when script tobe run. |
31 | onerror | script | element error occurs when script tobe run. |
32 | onmousewheel | script | mouse wheel will be rotate when script tobe run. |
33 | onscroll | script | scrollbar is scroll when script tobe run. |
34 | onresize | script | element should be resize when script tobe run. |
35 | onselect | script | all element content selected when script tobe run. |
36 | onstorage | script | element should be store in target when script tobe run. |
Browser Compatibility
Sno | Browser | Support |
1 | Chrome | Yes |
2 | Firefox | Yes |
3 | Edge | Yes |
4 | Opera | Yes |
5 | Safari | Yes |
6 | Internet Explorer | Yes |