Lesson

HTML Video

10 min reading
Free Course

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, 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>

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 autoplay without muted: Modern Chrome, Firefox, and Safari block unmuted autoplay automatically.
  • Omitting playsinline on mobile background videos: Without playsinline, iOS Safari forces auto-playing videos into fullscreen mode.
  • Putting 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.

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.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
HTML Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum