Codectionary / Developer documentation / HTML

<video>

The <video> element embeds video content directly in a web page without needing a third-party plugin. It supports built-in playback controls, multiple source formats via nested <source> elements for browser compatibility, and various attributes for controlling autoplay, looping, and muting.

Syntax

<video src="movie.mp4" controls width="640"></video>

Examples

Basic Video Player

A video with standard browser playback controls.

<video controls width="640" height="360">
  <source src="video.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>

Multiple Source Formats

Providing fallback formats for broader browser support.

<video controls width="640">
  <source src="movie.webm" type="video/webm">
  <source src="movie.mp4" type="video/mp4">
  Your browser does not support HTML5 video.
</video>

Autoplay Muted Background Video

A common pattern for looping background videos.

<video autoplay muted loop playsinline style="width: 100%; object-fit: cover;">
  <source src="background.mp4" type="video/mp4">
</video>

Attributes

  • controls (boolean): Shows the browser's built-in playback controls
  • autoplay (boolean): Starts playback automatically (most browsers require muted for this to work)
  • loop (boolean): Restarts the video automatically when it ends
  • muted (boolean): Mutes audio by default
  • poster (URL): An image shown before playback starts

Best practices

  • Always include the controls attribute unless you have a very specific reason to hide them — autoplay-only videos are a poor user experience
  • Autoplay only works reliably in most browsers when combined with muted
  • Provide multiple <source> formats (MP4, WebM) for cross-browser compatibility
  • Include fallback text between the tags for very old browsers that do not support <video>
  • Use the poster attribute to show a meaningful thumbnail before playback

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation