Use the <video>
to embed video content in a document.
Content categories |
Flow content, phrasing content, embedded content. If it has a controls attribute: interactive content and palpable content. |
---|---|
Permitted content | If the element has a Else: zero or more |
Tag omission | None, both the starting and ending tag are mandatory. |
Permitted parents | Any element that accepts embedded content. |
Permitted ARIA roles | application |
DOM interface | HTMLVideoElement |
Like all other HTML elements, this element supports the global attributes.
autoplay
Sites which automatically play audio (or videos with an audio track) can be an unpleasant experience for users, so it should be avoided when possible. If you must offer autoplay functionality, you should make it opt-in (requiring a user to specifically enable it). However, this can be useful when creating media elements whose source will be set at a later time, under user control.
To disable video autoplay, autoplay="false"
will not work; the video will autoplay if the attribute is there in the <video>
tag at all. To remove autoplay the attribute needs to be removed altogether.
buffered
TimeRanges
object.controls
crossorigin
<canvas>
element without being tainted. The allowed values are: Origin:
HTTP header without a cookie, X.509 certificate, or performing HTTP Basic authentication. If the server does not give credentials to the origin site (by not setting the Access-Control-Allow-Origin:
HTTP header), the image will be tainted, and its usage restricted.Origin:
HTTP header with a cookie, a certificate, or performing HTTP Basic authentication. If the server does not give credentials to the origin site (through Access-Control-Allow-Credentials:
HTTP header), the image will be tainted and its usage restricted.Origin:
HTTP header), preventing its non-tainted used in <canvas>
elements. If invalid, it is handled as if the enumerated keyword anonymous was used. See CORS settings attributes for additional information.height
loop
muted
played
TimeRanges
object indicating all the ranges of the video that have been played.preload
none
: indicates that the video should not be preloaded.metadata
: indicates that only video metadata (e.g. length) is fetched.auto
: indicates that the whole video file could be downloaded, even if the user is not expected to use it.auto
value.If not set, its default value is browser-defined (i.e. each browser may have its default value). The spec advises it to be set to metadata
.
autoplay
attribute has precedence over preload
. If autoplay
is specified, the browser would obviously need to start downloading the video for playback.poster
src
<source>
element within the video block to specify the video to embed.width
playsinline
The <video>
element can fire many different events.
<video>
element contains one or more video sources. To specify a video source, use either the src
attribute or the <source>
element; the browser will choose the most suitable one. For a list of supported formats, see Media formats supported by the audio and video elements.<!-- Simple video example --> <video src="videofile.webm" autoplay poster="posterimage.jpg"> Sorry, your browser doesn't support embedded videos, but don't worry, you can <a href="videofile.webm">download it</a> and watch it with your favorite video player! </video> <!-- Video with subtitles --> <video src="foo.webm"> <track kind="subtitles" src="foo.en.vtt" srclang="en" label="English"> <track kind="subtitles" src="foo.sv.vtt" srclang="sv" label="Svenska"> </video>
The first example plays a video, starting playback as soon as enough of the video has been received to allow playback without pausing to download more. Until the video starts playing, the image "posterimage.jpg" is displayed in its place.
The second example allows the user to choose between different subtitles.
This example offers three different sources for the media; this allows the video to be watched regardless of which video codecs are supported by the browser; first WebM is tried. If that can't be played, then MP4 is tried. Finally, OGG is tried.
<video width="480" controls poster="https://archive.org/download/WebmVp8Vorbis/webmvp8.gif" > <source src="https://archive.org/download/WebmVp8Vorbis/webmvp8.webm" type="video/webm"> <source src="https://archive.org/download/WebmVp8Vorbis/webmvp8_512kb.mp4" type="video/mp4"> <source src="https://archive.org/download/WebmVp8Vorbis/webmvp8.ogv" type="video/ogg"> Your browser doesn't support HTML5 video tag. </video>
You can try the preceding example on HTML5 video demo example with live preview code editor.
If the MIME type for the video is not set correctly on the server, the video may not show or show a gray box containing an X (if JavaScript is enabled).
If you use Apache Web Server to serve Ogg Theora videos, you can fix this problem by adding the video file type extensions to "video/ogg" MIME type. The most common video file type extensions are ".ogm", ".ogv", or ".ogg". To do this, edit the "mime.types" file in "/etc/apache" or use the "AddType" configuration directive in httpd.conf.
AddType video/ogg .ogm AddType video/ogg .ogv AddType video/ogg .ogg
If you serve your videos as WebM, you can fix this problem for the Apache Web Server by adding the extension used by your video files (".webm" is the most common one) to the MIME type "video/webm" via the "mime.types" file in "/etc/apache" or via the "AddType" configuration directive in httpd.conf.
AddType video/webm .webm
Your web host may provide an easy interface to MIME type configuration changes for new technologies until a global update naturally occurs.
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of '<video>' in that specification. | Living Standard |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 3 | Yes | 3.5 | 9 | 10.5 | 3.1 |
autoplay |
3 | Yes | 3.5 | 9 | 10.5 | 3.1 |
buffered |
? | Yes | 4 | ? | Yes | ? |
controls |
3 | Yes | 3.5 | 9 | 10.5 | 3.1 |
crossorigin |
? | Yes | 12 | ? | ? | ? |
height |
3 | Yes | 3.5 | 9 | 10.5 | 3.1 |
loop |
3 | Yes | 11 | 9 | 10.5 | 3.1 |
muted |
30 | Yes | 11 | 10 | Yes | 5 |
played |
? | Yes | 15 | ? | Yes | ? |
poster |
3 | Yes | 3.6 | 9 | 10.5 | 3.1 |
preload |
3 | Yes | 4 | 9 | Yes | 3.1 |
src |
3 | Yes | 3.5 | 9 | 10.5 | 3.1 |
width |
3 | Yes | 3.5 | 9 | 10.5 | 3.1 |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic support | Yes | Yes | Yes | 4 | ? | Yes | Yes |
autoplay |
Yes | Yes | Yes | 4 | 8.1 | Yes | 101 |
buffered |
? | ? | Yes | 4 | ? | Yes | ? |
controls |
Yes | Yes | Yes | 4 | ? | Yes | Yes |
crossorigin |
? | ? | Yes | 14 | ? | ? | ? |
height |
Yes | Yes | Yes | 4 | ? | Yes | Yes |
loop |
Yes | Yes | Yes | 14 | 8 | Yes | 6 |
muted |
Yes | Yes | Yes | 14 | 8 | Yes | ? |
played |
? | ? | Yes | 15 | ? | Yes | ? |
poster |
Yes | Yes | Yes | 4 | ? | Yes | Yes |
preload |
Yes | Yes | Yes | 4 | ? | Yes | Yes |
src |
Yes | Yes | Yes | 4 | ? | Yes | Yes |
width |
Yes | Yes | Yes | 4 | ? | Yes | Yes |
1. Only available for videos that have no sound or have the audio track disabled.
<audio>
nsIDOMHTMLMediaElement
video
element (HTML5 specification)
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video