Nearby lessons
14 of 24๐ฌ HTML <video> Element
๐ What is HTML Video?
The
<video> element in HTML is used to embed video content. It supports various attributes like controls, autoplay, muted, and formats like MP4 and WebM for wide browser compatibility.๐ฅ Basic Usage
The
<video> tag allows you to display video files directly in your browser with optional built-in controls.Code Example
PREVIEW READY
โฏ๏ธ Autoplay Behavior
To autoplay a video, most browsers require it to be muted as well.
Code Example
PREVIEW READY
๐ผ Supported Video Formats
| Attribute | Description |
|---|---|
MP4 | ๐ฏ Most widely supported format across all major browsers |
WebM | ๐ Open format with good compression and performance |
Ogg | ๐ฐ๏ธ Older format with limited support |
โ๏ธ Common Attributes
| Attribute | Description |
|---|---|
controls | Shows video player controls (play, pause, volume) |
autoplay | Starts playing video automatically (usually with muted) |
loop | Repeats the video once it finishes |
muted | Starts the video with no sound |
poster | Image to display before the video plays |
preload | Instructs browser how to preload the video: auto, metadata, none |
๐งช Video API (JavaScript)
- Methods:
play(),pause(),load() - Properties:
currentTime,volume,duration - Events:
play,pause,ended
โ Best Practices
- โ
Always include
controlsif no custom player is used - โ
Use
posterto show a thumbnail before playback - โ Provide multiple formats for better compatibility
- โ
Mute the video if using
autoplay - โ
Use
<track>for subtitles and accessibility
๐ Poster Image Example
The
poster attribute adds a preview image before the video starts playing.Code Example
PREVIEW READY
๐ง Test Your Knowledge
5 QuestionsProgress: 0 / 5
Keep Going!HTML Youtube