<video> Tag in HTML

Quick facts

CategoryFlow content, phrasing content, embedded content
Content modelIf src is set: fallback content for unsupported browsers. If not: one or more <source> elements, then fallback content
Tag omissionNeither the start nor end tag can be omitted
Permitted parentsAny element that accepts embedded content
DOM interfaceHTMLVideoElement

Syntax

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

Live example

Uses “Big Buck Bunny” (Blender Foundation, CC BY 3.0) as a public sample video.

index.html
Preview

Attributes

AttributeDescription
srcPath or URL to the video file (omit if using nested <source> elements)
controlsShows the browser’s built-in play/pause/volume controls
autoplayStarts playback automatically — most browsers require muted alongside it
loopRestarts playback automatically when it ends
mutedStarts the video with sound off
posterImage shown before playback starts
width / heightDisplay dimensions in pixels

Common examples

A video with controls and a poster image

The poster is shown before playback starts; preload="metadata" avoids downloading the whole file up front.

<video src="intro.mp4" controls poster="intro-cover.jpg" preload="metadata" width="640" height="360"> Your browser does not support video. </video>

A silent background video

Autoplay only works reliably when the video is muted; playsinline stops iPhones from opening it full screen.

<video src="waves.mp4" autoplay muted loop playsinline></video>

Captions with a text track

Add a WebVTT file with <track> so viewers can turn on subtitles.

<video src="talk.mp4" controls> <track src="talk-en.vtt" kind="captions" srclang="en" label="English" default> </video>

<video> vs embedding YouTube

With the <video> tag you host the file yourself: you control the player, there is no third-party branding or tracking, and the video is always available. The cost is bandwidth and storage, and you need to prepare the files (compression, formats, captions) yourself.

Embedding a YouTube or Vimeo video with an <iframe> hands the hosting, streaming quality and compression to the platform, and your video can also be found on that platform. For short clips, background loops and product animations, <video> works well; for long videos you want watched and shared, embedding is usually easier.

<video>YouTube embed
Hosting costYoursFree (platform)
Player controlFullLimited
Best forShort clips, loopsLong videos, reach

Common mistakes to avoid

  • Autoplay with sound. Browsers block it. Add muted, or let the visitor press play.
  • No controls. Without controls, visitors can’t pause, seek or change the volume (unless you build your own controls).
  • Huge video files on your own hosting. Large videos are slow and costly to serve; compress them or host them on a video platform and embed it with an <iframe>.
  • No captions. Many people watch with the sound off; captions also make your video accessible to deaf and hard-of-hearing viewers.

Accessibility & SEO tips

  • Provide captions with <track> and, for important videos, a text transcript on the page — search engines can read text but not speech.
  • Never autoplay video with sound, and make sure moving background video can be paused.
  • Make videos responsive with video { width: 100%; height: auto; } and keep the width and height attributes to avoid layout shift.
  • Compress videos before uploading and keep background loops short (a few seconds), so they don’t slow the page down on mobile data.

Browser support

Supported in all modern browsers. MP4 (H.264 video) plays everywhere; WebM is a smaller open format supported by all current browsers, so offering both covers every visitor.

Related tags

Frequently asked questions

Why won't my video autoplay?
Most browsers block autoplay with sound to avoid unwanted noise. Add the muted attribute alongside autoplay to allow it.
How do I offer multiple video formats?
Omit src on <video> and add multiple <source src="..." type="..."> children — the browser uses the first one it can play.
How do I embed a YouTube video?
Use YouTube's Share → Embed code, which is an <iframe>, rather than <video>. The <video> tag is for video files you host yourself.
Which video format should I use?
MP4 with H.264 video is the safest choice and plays in every browser. Add a WebM version as an extra <source> if you want smaller files.
How do I make a video responsive?
Add video { width: 100%; height: auto; } in CSS. The video then scales to its container while keeping its shape.
How do I add a thumbnail image to a video?
Use the poster attribute, for example <video src="clip.mp4" poster="cover.jpg" controls>. The poster image is shown until the visitor presses play, and it is a good place for a title frame that explains what the video is about.