The HTML <video> element lets you embed video files directly into your web pages. No extra plugins needed. Just pure HTML.
The video Element
To add a video to your page, use the <video> tag. You can specify multiple video formats so the browser can pick the one it supports.
The controls attribute adds play, pause, and volume buttons. Always include it so users can control the video.
How It Works
You put <source> tags inside the <video> element. Each <source> points to a different video format. The browser picks the first one it can play.
Always include width and height. This reserves space on the page and prevents flickering while the video loads.
Autoplay Videos
You can make a video start automatically with the autoplay attribute. However, most browsers block autoplay with sound. To autoplay, you must also mute the video.
muted attribute along with autoplay.
Loop and Poster Attributes
The loop attribute makes the video repeat. The poster attribute shows an image before the video starts playing.
Supported Video Formats
There are three main video formats supported by HTML. MP4 is the safest choice because it works everywhere.
| Format | File Extension | Browser Support |
|---|---|---|
| MP4 | .mp4 | ✅ All browsers (recommended) |
| WebM | .webm | ✅ All modern browsers |
| OGG | .ogg | ✅ All modern browsers |
Media Types (MIME Types)
When using <source>, always specify the type attribute with the correct MIME type.
| File Format | Media Type |
|---|---|
| MP4 | video/mp4
|
| WebM | video/webm
|
| OGG | video/ogg
|
Controlling Video with JavaScript
You can control videos with JavaScript. This example uses buttons to play, pause, and reset the video.
Quick Summary
- Use
<video>to embed videos. Always includecontrols. - Use
<source>inside to provide multiple formats. MP4 is the safest. - Set
widthandheightto prevent page flickering. - Use
autoplay mutedif you want videos to start automatically. - Use
loopto repeat the video. - Use
posterto show an image before the video plays. - You can control videos with JavaScript using
.play(),.pause(), and.currentTime.
What Just Happened? Let Me Explain
- The
<video>tag is supported in all modern browsers. You no longer need Flash or other plugins. - MP4 with H.264 video and AAC audio is the most compatible format. Use it for all your web videos.
- Browsers block autoplay with sound to protect users from unexpected noise. If you want autoplay, mute the video.
- The text inside the
<video>tag only shows in very old browsers that do not support the video tag. - You can host video files on your own server, but video files are large. Consider using a video hosting service like YouTube or Vimeo for better performance.
HTML Video Reference
| Tag / Attribute | Description |
|---|---|
<video>
| Defines a video or movie |
<source>
| Defines multiple media resources (for <video> and <audio>) |
controls
| Adds play, pause, and volume buttons |
autoplay
| Starts the video automatically |
muted
| Mutes the video (required for autoplay) |
loop
| Repeats the video when it ends |
poster
| Shows an image before the video starts |