Skip to main content

HTML Tags

HTML <video> Tag

Written by Updated HTML <video> Tag exercises

The video tag plays video right in the page with the browser's own player. With controls, a poster image and an MP4 source, you have a working player in four lines, no plugin or library needed.

This is the tag reference. A longer walk-through of formats, autoplay and captions is in HTML Video.

Syntax

html

<video controls>
  <source src="video.mp4" type="video/mp4">
  <source src="video.webm" type="video/webm">
  Your browser does not support the video tag.
</video>
AttributeWhat it doesExample
srcThe video file, if you use only onesrc="movie.mp4"
controlsShows play, pause, volume and fullscreencontrols
posterAn image shown before playingposter="thumb.jpg"
width, heightThe player size in pixelswidth="640"
autoplayStarts by itself, only if also mutedautoplay muted
mutedStarts with no soundmuted
loopStarts again at the endloop
playsinlinePlays inside the page on iPhonesplaysinline
preloadHow much to load before play: none, metadata, autopreload="metadata"

Example

html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Video Tag Example</title>
</head>
<body>
  <h2>Example: Embedding a Video</h2>

  <video width="640" height="360" controls poster="https://ik.imagekit.io/html5andcss3/lesson-samples/sample_thumbnail.png">
    <source src="https://ik.imagekit.io/html5andcss3/lesson-samples/sample_video.mp4" type="video/mp4">
    <source src="https://ik.imagekit.io/html5andcss3/lesson-samples/sample_video.webm" type="video/webm">
    Your browser does not support the video tag.
  </video>

</body>
</html>

A 640 by 360 player appears with a poster image. The browser plays the MP4 if it can, and the WebM otherwise.

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

Good to know

  • Add captions with the track tag.
  • Make it responsive with video { max-width: 100%; height: auto; }.
  • For long or popular videos, a video hosting service usually streams better than a single file on your server.

HTML <video> Tag exercises

Add a video player

Add a video player with controls for this file: https://ik.imagekit.io/html5andcss3/lesson-samples/sample_video.mp4

Result

Check your answer to see it here.