- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <video> Tag
HTML Tags
HTML <video> Tag
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>| Attribute | What it does | Example |
|---|---|---|
| src | The video file, if you use only one | src="movie.mp4" |
| controls | Shows play, pause, volume and fullscreen | controls |
| poster | An image shown before playing | poster="thumb.jpg" |
| width, height | The player size in pixels | width="640" |
| autoplay | Starts by itself, only if also muted | autoplay muted |
| muted | Starts with no sound | muted |
| loop | Starts again at the end | loop |
| playsinline | Plays inside the page on iPhones | playsinline |
| preload | How much to load before play: none, metadata, auto | preload="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+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
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.
