HTML - <video>
Use the HTML <video>
element to embed video content in a document. The 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.
Example
<!-- 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.
Description
Use the HTML <video>
element to embed video content in a document. The 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.
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 parent elements | Any element that accepts embedded content. |
DOM interface | HTMLVideoElement |
Browser Compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 3.0 | 3.5 (1.9.1) | 9.0 | 10.5 | 3.1 |
autoplay attribute |
3.0 | 3.5 (1.9.1) | 9.0 | 10.5 | 3.1 |
buffered attribute |
? | 4.0 (2.0) | ? | (Yes) | ? |
controls attribute |
3.0 | 3.5 (1.9.1) | 9.0 | 10.5 | 3.1 |
crossorigin attribue |
? | 12.0 (12.0) | ? | ? | ? |
loop attribute |
3.0 | 11.0 (11.0) | 9.0 | 10.5 | 3.1 |
muted attribute |
30.0 | 11.0 (11.0) | 10.0 | (Yes) | 5.0 |
played property |
? | 15.0 (15.0) | ? | (Yes) | ? |
poster attribute |
3.0 | 3.6 (1.9.2) | 9.0 | 10.5 | 3.1 |
preload attribute |
3.0 | 4.0 (2.0) | 9.0 | (Yes) | 3.1 |
src attribute |
3.0 | 3.5 (1.9.1) | 9.0 | 10.5 | 3.1 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | 1.0 (1.0) | ? | ? | ? |
autoplay attribute |
? | 1.0 (1.0) | 8.1 | ? | 10.0[1] |
buffered attribute |
? | 4.0 (2.0) | ? | ? | ? |
controls attribute |
? | 1.0 (1.0) | ? | ? | ? |
loop attribute |
? | 11.0 (11.0) | 8.0 | ? | 6.0 |
muted attribute |
? | 11.0 (11.0) | 8.0 | ? | ? |
played property |
? | 15.0 (15.0) | ? | ? | ? |
poster attribute |
? | 1.0 (1.0) | ? | ? | ? |
preload attribute |
? | 4.0 (2.0) | ? | ? | ? |
src attribute |
? | 1.0 (1.0) | ? | ? | ? |
crossorigin attribute |
? | 12.0 (12.0) | ? | ? | ? |
[1] As of iOS 10, autoplay is allowable only for videos that have no sound or have the audio track disabled
See Also
Events
The <video>
element can fire many different events.
Multiple Sources Example
<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.
Server support
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.
DOM interface
This element implements the HTMLVideoElement
interface.
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/html/element/video