HTML Video
The HTML <video>
element is used to show a video on a web page.
<!DOCTYPE html> <html> <body> <video width="400" controls> <source src="videos/movie.mp4" type="video/mp4"> <source src="videos/movie.ogg" type="video/ogg"> Your browser does not support HTML video. </video> </body> </html>
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.
HTML <video> Autoplay
To start a video automatically use the autoplay
attribute:
<!DOCTYPE html> <html> <body> <video width="320" height="240" autoplay> <source src="videos/movie.mp4" type="video/mp4"> <source src="videos/movie.ogg" type="video/ogg"> Your browser does not support the video tag. </video> <p><b>Note:</b> The autoplay attribute does not work on some mobile devices.</p> </body> </html>
The autoplay attribute does not work in mobile devices like iPad and iPhone.