HTML Video

HTML Tutorial

HTML Forms

HTML Graphics

HTML Media

HTML API

HTML Video

The HTML <video> element displays a video on a web page

				
					<video width="400" controls>
  <source src="mov_bbb.mp4" type="video/mp4">
  <source src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML video.
</video>

				
			

The HTML <video> Element

Using the <video> element displays a video in HTML:

				
					<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">

				
			

How it Functions

  • The controls attribute is used for adding the video controls, like play, pause, and volume.
  • Always include width and height attributes. The page may flicker when the video loads if the height and width are not set.
  • The <source> element specifies alternative video files, chosen by the browser. The browser recognizes the first used format.

HTML <video> Autoplay

Using the autoplay attribute, starts a video automatically:

				
					<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>

				
			

HTML Video – Methods, Properties, and Events

  • The HTML DOM specifies methods, properties, and events for the <video> element.
  • It enables you to load, play, and pause videos, as well as set the duration and volume.

Example: Using JavaScript

				
					<div style="text-align:center"> 
  <button onclick="playPause()">Play/Pause</button> 
  <button onclick="makeBig()">Big</button>
  <button onclick="makeSmall()">Small</button>
  <button onclick="makeNormal()">Normal</button>
  <br><br>
  <video id="video1" width="420">
    <source src="mov_bbb.mp4" type="video/mp4">
    <source src="mov_bbb.ogg" type="video/ogg">
    Your browser does not support HTML video.
  </video>
</div> 
<script> 
var myVideo = document.getElementById("video1"); 
function playPause() { 
  if (myVideo.paused) 
    myVideo.play(); 
  else 
    myVideo.pause(); 
} 

function makeBig() { 
    myVideo.width = 560; 
} 
function makeSmall() { 
    myVideo.width = 320; 
} 
function makeNormal() { 
    myVideo.width = 420; 
} 
</script>