Skip to main content

HTML Video

The <video> element is used to show a video on a web page.


The HTML <video> Element

To show a video in HTML, use the <video> element, with one or more <source> elements for the video files.

Example

A video with controls and two source formats.

Prompt
A 320x240 video with the controls attribute and two source files (movie.mp4 and movie.ogg), plus fallback text for browsers that do not support the video tag.
Output: complete HTML page

How it Works

The controls attribute adds video controls like play, pause, and volume. It is a good idea to always set width and height, or the page may flicker while the video loads. The <source> element lets you offer several video files; the browser uses the first format it recognizes. The text between <video> and </video> shows only in browsers that do not support the element.


HTML <video> Autoplay

To start a video automatically, use the autoplay attribute.

Note: Chromium browsers usually block autoplay, but muted autoplay is always allowed. Add muted after autoplay to let the video start automatically (but muted).

Autoplay

A video that starts automatically.

Prompt
A 320x240 video that starts playing automatically using the autoplay attribute, with mp4 and ogg sources and fallback text.
Output: complete HTML page

Autoplay muted

A video that autoplays muted so it works in Chromium browsers.

Prompt
A 320x240 video that autoplays muted (autoplay and muted attributes), with mp4 and ogg sources and fallback text, so it can start automatically in Chromium browsers.
Output: complete HTML page

Browser Support

The <video> element is supported in all modern browsers (from Chrome 4, Edge 9, Firefox 3.5, Safari 4, and Opera 10.5).


HTML Video Formats

HTML supports three video formats: MP4, WebM, and Ogg. MP4 and WebM work in all major browsers; Ogg works everywhere except Safari.


HTML Video - Media Types

The media types for the supported formats are: MP4 is video/mp4, WebM is video/webm, and Ogg is video/ogg.


HTML Video - Methods, Properties, and Events

The HTML DOM defines methods, properties, and events for the <video> element. These let you load, play, and pause videos, set the duration and volume, and respond to events such as a video starting or being paused.

Using JavaScript

Buttons that play, pause, and resize a video with JavaScript.

Prompt
A page that controls a video with JavaScript: buttons to play/pause the video and to resize it bigger, smaller, or back to normal, using the DOM video methods and properties.
Output: complete HTML page

HTML Video Tags

The video-related tags are: <video> (defines a video), <source> (defines several media resources for <video> and <audio>), and <track> (defines text tracks in media players).