Integrate Video in HTML: The <video> Tag

Learn to embed, control, and add captions to videos to make your web pages more dynamic and accessible.

Lesson ProgressStep 1 of 9
🖼️
▶️
🔊
Subtitles will appear here...
0 EXP

Welcome! Let's learn how to bring your websites to life with the HTML <video> tag.

The <video> Tag

The <video> tag is the HTML5 element for embedding a video player. At its simplest, you use the src attribute to point to your video file.

<video src="my-awesome-video.mp4"></video>

However, this code by itself is not very useful. It just shows the first frame of the video (or a black box) and gives the user no way to play it. To make it functional, we need attributes.

System Check

Which attribute is essential to show the play, pause, and volume controls?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🎬
Video Embed Master

Embed a video with controls and a poster image.

📦
Source Pro

Use the <source> tag to provide multiple video formats.

🎧
A11y Champion

Make your video accessible by adding a <track> for captions.

Mission: Embed a Complete Video Player

Using the template, add two <source> tags: one for "video.mp4" and one for "video.webm". Make sure they have the correct `type` attributes.

A.D.A. Feedback:

> System integrity looks stable. Code is valid.

Challenge: Assemble the Video Element

Drag the elements into the correct order to create a valid video element with multiple sources.

<source src="video.mp4" type="video/mp4">
<video controls>
</video>
<source src="video.webm" type="video/webm">

Challenge: Add Accessibility

Fill in the missing parts to add an English captions track to this video.

<video controls>...<kind=""="caps.vtt"="en">...</video>

Consult A.D.A.

Unlock with Premium

Community Holo-Net

Peer Project Review

Submit your "Accessible Video Player" project for feedback from other Net-Runners.

Beyond Play: Mastering the HTML Video Element

Embedding a video is no longer a complex task requiring third-party plugins. Thanks to the HTML5 <video> element, adding rich multimedia is as simple as adding an image. However, mastering this tag involves more than just the src attribute. A professional, robust video implementation considers compatibility, accessibility, performance, and user experience.

The Anatomy of a Robust Video Element

Let's look at a complete, production-ready video element and break down its parts.

<video controls preload="metadata" poster="images/thumbnail.jpg" width="640" height="360">
  <source src="videos/my-video.webm" type="video/webm">
  <source src="videos/my-video.mp4" type="video/mp4">
  <track src="captions/captions.vtt" kind="captions" srclang="en" label="English">
  <track src="subtitles/subtitles_es.vtt" kind="subtitles" srclang="es" label="Español">
  <p>Your browser doesn't support embedded videos. You can <a href="videos/my-video.mp4">download it</a> instead.</p>
</video>

1. Essential Attributes for Control

Attributes are the settings for your video player. The most critical ones are:

  • controls: A boolean attribute that displays the browser's default user interface for playback (play/pause, volume, fullscreen, etc.). Without this, the user can't control the video (unless you build your own controls with JavaScript).
  • width / height: Setting these prevents the page layout from "jumping" as the video loads. It's crucial for good Core Web Vitals.
  • autoplay: A boolean attribute that, if present, will *try* to play the video automatically. **Warning:** Nearly all modern browsers will block autoplay unless the muted attribute is also present.
  • muted: Mutes the video by default. This is the key to making autoplay work.
  • loop: Makes the video automatically restart when it finishes.

2. Solving the Compatibility Puzzle with <source>

There is no single video format (codec) that is supported by 100% of browsers. This is where the <source> tag becomes essential.

  • The <video> tag acts as a container. Inside it, you list multiple <source> elements.
  • The browser reads the list from top to bottom and plays the **first one** it understands.
  • Best Practice: Provide **WebM** first, as it offers superior compression and quality. Follow it with **MP4 (H.264)**, which provides the near-universal fallback for browsers that don't support WebM (like Safari).
  • The type attribute is critical. It tells the browser the MIME type of the file, so it doesn't waste time downloading a file it can't play.

3. Accessibility is Non-Negotiable: The <track> Tag

A silent video is an inaccessible video for many users. The <track> tag is the solution. It overlays timed text over the video, using a WebVTT (.vtt) file format.

The kind attribute is the most important:

  • kind="captions": For users who are deaf or hard of hearing. Includes all spoken dialogue **and** other important sounds (e.g., "[door slams]", "[tense music]").
  • kind="subtitles": A translation of the dialogue for users who speak a different language.
  • kind="descriptions": For users who are blind or visually impaired. An audio-description track that describes on-screen visuals.
  • kind="chapters": Used to create navigation points within the video.

The text between the opening <video> and closing </video> tags (after all <source> and <track> tags) is the **fallback content**. It is only displayed by ancient browsers that don't understand the video tag at all.

4. Performance & User Experience

Video files are large. How you load them matters.

The preload Attribute

  • preload="none": Doesn't load *anything* until the user hits play. Saves the most data.
  • preload="metadata": Loads only the video's metadata (duration, dimensions, etc.). This is the recommended default.
  • preload="auto": Lets the browser decide. It may download the entire video, which can waste bandwidth.

The poster Attribute

This attribute specifies an image to display before the video loads or while it's downloading. It's crucial for two reasons:

  • It prevents a "black box" from appearing on your page.
  • It provides a visually appealing preview of the content.
Key Takeaway: A modern <video> element is more than a src. It's responsive (with CSS), compatible (with <source>), accessible (with <track>), and performant (with preload and poster).

HTML Video & Multimedia Glossary

<video>
The main HTML5 element used to embed a video player and its content into a document.
<source>
A self-closing tag nested inside a <video> element. It allows you to specify multiple alternative video files (formats) for the browser to choose from.
<track>
A self-closing tag used to specify timed text tracks (like captions or subtitles) for a video. It requires a .vtt file.
controls (Attribute)
A boolean attribute for the <video> tag. When present, it displays the browser's default video controls.
autoplay (Attribute)
A boolean attribute that attempts to start the video playing as soon as it can. This will be blocked by most browsers unless the muted attribute is also present.
muted (Attribute)
A boolean attribute that mutes the video's audio by default.
poster (Attribute)
Specifies the URL of an image to be displayed as a placeholder before the video starts playing.
preload (Attribute)
An attribute that hints to the browser how much of the video file to download when the page loads. Values are none, metadata, or auto.
kind (Attribute)
A required attribute for the <track> tag that specifies the purpose of the text track. Common values are captions, subtitles, and descriptions.
srclang (Attribute)
An attribute for the <track> tag that specifies the language of the track text (e.g., "en", "es", "fr").
WebVTT
(Web Video Text Tracks, .vtt file). The standard format for writing timed text files for use with the <track> element.
MIME Type
A string sent with a file indicating its format (e.g., "video/mp4", "video/webm"). Used in the type attribute of the <source> tag.
Codec
(Encoder/Decoder). The software used to compress and decompress a video file. The file format (like MP4) is just a container; the codec (like H.264 or AV1) is what does the work.
Fallback Content
The content (usually a paragraph and a download link) placed just before the closing </video> tag. It is only displayed by very old browsers that do not support the <video> element.

Credibility and Trust

About the Author

Author's Avatar

Todotutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching HTML and building robust and accessible web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest HTML5 specifications and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!