<video>
A video player embedded directly in the page.
- Display
- inline (replaced element)
- Closing tag
- Required
- Permitted content
<source>and<track>elements, followed by fallback content
Example
#<video controls width="300" height="200" preload="none" poster="/collections/covers/od-czego-zaczac-nauke-programowania.webp">
<source src="/media/lekcja-1.webm" type="video/webm">
<source src="/media/lekcja-1.mp4" type="video/mp4">
<track kind="captions" src="/media/lekcja-1-pl.vtt" srclang="pl" label="Polish" default>
<a href="/media/lekcja-1.mp4">Download the lesson as MP4</a>
</video>The video file and the captions are skipped in the preview, so you see only the poster and the controls.
Definition and usage
#The <video> element displays a video from a file without any external plugins. You give the source in the src attribute or in several <source> elements with different formats, and you add subtitles with <track> elements.
The controls attribute shows the built-in playback bar, and poster sets an image shown before the video starts. It is also worth providing width and height, so the browser reserves space for the player before the video loads.
Autoplay usually works only when muted, which is why short background animations are written as autoplay muted loop playsinline. You canโt embed videos from services like YouTube with <video>. For those, use an <iframe> with the code the service provides.
Syntax
#<video src="video.mp4" controls width="โฆ" height="โฆ"></video>Attributes
#src
URL
The address of the video file. When you want to offer several formats, use<source>elements inside<video>instead ofsrc.boolean attribute
Shows the built-in controls: play, timeline, volume, full screen. Without them the user has no way to control the video, unless you build your own buttons.image URL
An image displayed before the video starts. Without it the player shows the first frame of the video, or an empty rectangle until that frame loads.width / height
number of pixels
The dimensions of the player. The video is fitted to this area while keeping its proportions, and with different proportions empty bars appear.autoplay
boolean attribute
Starts the video right after loading. Browsers usually allow this only when the video is muted with themutedattribute.muted
boolean attribute
Starts the video with the sound off. In practice essential withautoplay.loop
boolean attribute
When the video reaches the end, it starts again from the beginning.playsinline
boolean attribute
On iPhone, plays the video in place on the page instead of automatically switching to full screen. Important for short background animations.preload
none | metadata | auto
How much data to download in advance. On a page with many videos, setnoneormetadataso you donโt waste bandwidth.
The element also supports all global attributes, such as class, id, style and hidden.
Attributes in practice
#controls
boolean attributeShows the built-in controls: play, timeline, volume, full screen. Without them the user has no way to control the video, unless you build your own buttons.
<video src="/media/lekcja-2.mp4" controls width="240" height="160" preload="none" poster="/collections/covers/programowanie-dla-dzieci.webp"></video>The video file is skipped in the preview.
poster
image URLAn image displayed before the video starts. Without it the player shows the first frame of the video, or an empty rectangle until that frame loads.
<video src="/media/gra-w-kodowanie.mp4" controls width="240" height="160" preload="none" poster="/collections/covers/gry-do-nauki-programowania.webp"></video>The video file is skipped in the preview, only the poster is visible.
More examples
#<video autoplay muted loop playsinline width="300" height="200" poster="/collections/covers/vibe-coding.webp">
<source src="/media/tlo-animacja.webm" type="video/webm">
<source src="/media/tlo-animacja.mp4" type="video/mp4">
</video>The video file is skipped in the preview, so only the poster is visible. On a real page the animation loops without sound.
Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Add subtitles with
<track kind="captions">. Many people watch videos without sound, and for deaf people captions are the only way to follow along. - Donโt upload huge files straight from the camera to the server. Compress the video and consider a lighter format, for example WebM, with MP4 as a fallback.
- For YouTube or Vimeo videos, use an
<iframe>with the embed code from the service, not<video>.
Related entries
#- <audio>An audio player: a podcast, a narration, a sound effect.
- <source>An alternative source of an image, audio, or video for `<picture>`, `<audio>`, and `<video>`.
- <track>A file with subtitles, descriptions, or chapters for `<video>` and `<audio>`.
- <iframe>A frame that embeds another HTML document in the page, for example a YouTube video or a map.
- <figure>A self-contained illustration with an optional caption: an image, chart, code snippet, or quote.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.