HTML Video Tutorial

Learn how to embed and control video content in your HTML pages

Introduction to HTML Video

The HTML <video> element allows you to embed video content directly in your web pages. It supports multiple video formats and provides built-in controls for playback.

Basic Syntax:

Basic Video Examples

1. Basic Video Player

The simplest way to embed a video with default controls.

2. Multiple Video Sources

Provide multiple formats for better browser compatibility.

3. Video with Poster Image

Show a preview image before the video plays.

Video Attributes

AttributeDescriptionExample
controlsShows the default video controls (play/pause, volume, etc.)<video controls>
autoplayVideo starts playing as soon as it's ready (may be blocked by browsers)<video autoplay>
loopVideo will start over again when finished<video loop>
mutedVideo will be muted by default<video muted>
posterURL of an image to show while video is downloading<video poster="image.jpg">
preloadSpecifies if/how the video should be loaded when page loads (auto, metadata, none)<video preload="auto">
widthSets the width of the video player in pixels<video width="600">
heightSets the height of the video player in pixels<video height="400">

Advanced Video Techniques

Custom Video Controls

Create your own controls using JavaScript instead of the default browser controls.

Video with Captions

Add subtitles/captions to your videos for accessibility.

Note: This example requires a WebVTT file for captions

Video Best Practices

Accessibility

  • Always provide controls for video playback
  • Include captions/subtitles for spoken content
  • Provide audio descriptions when needed
  • Don't autoplay videos with sound (it's often blocked anyway)
  • Ensure sufficient color contrast for any custom controls

Performance

  • Use MP4 format for broadest compatibility (H.264 codec)
  • Optimize video files (compression, appropriate resolution)
  • Use poster images for faster perceived loading
  • Consider lazy loading for videos below the fold
  • For large videos, consider streaming solutions

Browser Support

The HTML5 <video> element is supported in all modern browsers:

BrowserMP4WebMOgg
ChromeYesYesYes
FirefoxYesYesYes
SafariYesPartialNo
EdgeYesYesYes

Note: For widest compatibility, provide multiple formats (MP4 + WebM recommended).

< PreviousNext >