HTML Video
HTML Video: Embedding Clips, Controls, and Subtitles
The HTML video element embeds playable video directly inside your document using native browser controls. Supplying multiple source formats, a preview poster image, and WebVTT captions ensures fast loading and smooth playback across desktop and mobile devices.
Essential Video Attributes
controls: Renders the browser's built-in play/pause button, timeline scrubber, volume slider, and fullscreen toggle.poster: Displays a static thumbnail image before the user clicks play.preload="metadata": Loads only video duration and dimensions up front to save bandwidth.muted,autoplay, andplaysinline: Required together for silent looping hero videos on iOS Safari and Chrome.widthandheight: Reserve aspect-ratio space to prevent layout shifts while loading.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML Video Player Example</title>
<style>
.video-wrapper { max-width: 640px; }
video { width: 100%; height: auto; border-radius: 8px; background: #0f172a; }
</style>
</head>
<body>
<div class="video-wrapper">
<video controls poster="/images/course-preview.webp" preload="metadata" width="640" height="360">
<source src="/media/sample-video.mp4" type="video/mp4">
<source src="/media/sample-video.webm" type="video/webm">
<track src="/media/subtitles-en.vtt" kind="subtitles" srclang="en" label="English" default>
Your browser cannot play embedded MP4 or WebM video files.
</video>
</div>
</body>
</html>
Adding Subtitles with the track Element
The nested track tag attaches time-synced .vtt text tracks. Set kind="subtitles" for translations or kind="captions" when including sound cues like [music plays] for hard-of-hearing visitors.
Common Mistakes to Avoid
- Setting
autoplaywithoutmuted: Modern Chrome, Firefox, and Safari block unmuted autoplay automatically. - Omitting
playsinlineon mobile background videos: Withoutplaysinline, iOS Safari forces auto-playing videos into fullscreen mode. - Putting
srcon bothvideoand nestedsourcetags: When using multiplesourceelements, omitsrcon the outervideotag so fallback selection works cleanly.
Frequently Asked Questions
Which video format should appear first in source tags?
List smaller modern WebM (VP9/AV1) first if bandwidth is your priority, followed by universally supported MP4 (H.264) as the broad fallback.
How do I make an HTML video responsive?
Combine width and height HTML attributes with CSS width: 100%; height: auto; so the player shrinks cleanly on narrow mobile screens.
Unlock Your
Full Potential.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Try it Yourself
Experiment with the code from this lesson in our interactive playground.