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.
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, and playsinline: Required together for silent looping hero videos on iOS Safari and Chrome.width and height: 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>
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.
autoplay without muted: Modern Chrome, Firefox, and Safari block unmuted autoplay automatically.playsinline on mobile background videos: Without playsinline, iOS Safari forces auto-playing videos into fullscreen mode.src on both video and nested source tags: When using multiple source elements, omit src on the outer video tag so fallback selection works cleanly.List smaller modern WebM (VP9/AV1) first if bandwidth is your priority, followed by universally supported MP4 (H.264) as the broad fallback.
Combine width and height HTML attributes with CSS width: 100%; height: auto; so the player shrinks cleanly on narrow mobile screens.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.