video
elementcontrols
attribute: Interactive content.src
attribute: zero or more track
elements, then transparent, but with no media element descendants.src
attribute: zero or more source
elements, then zero or more
track
elements, then transparent, but with no media element descendants.src
crossorigin
poster
preload
autoplay
mediagroup
loop
muted
controls
width
height
interface HTMLVideoElement : HTMLMediaElement { attribute unsigned long width; attribute unsigned long height; readonly attribute unsigned long videoWidth; readonly attribute unsigned long videoHeight; attribute DOMString poster; };
A video
element is used for playing videos or movies, and audio files with
captions.
Content may be provided inside the video
element; it is intended for older Web browsers which do not support
video
,
so that legacy video plugins can be tried, or to show text to the
users of these older browsers informing them of how to access the
video contents.
In particular, this content is not intended to
address accessibility concerns. To make video content accessible to
the partially sighted, the blind, the hard-of-hearing, the deaf,
and those with other physical or cognitive disabilities, a variety
of features are available. Captions can be provided, either
embedded in the video stream or as external files using the
track
element. Sign-language tracks can be
provided, again either embedded in the video stream or by
synchronizing multiple video
elements using the mediagroup
attribute or a
MediaController
object. Audio
descriptions can be provided, either as a separate track embedded
in the video stream, or a separate audio track in an audio
element slaved to the same controller as
the video
element(s), or in text form using a
caption file
referenced using the track
element and synthesized into speech
by the user agent. WebVTT can also be used to provide chapter
titles. For users who would rather not use a media element at all,
transcripts or other textual alternatives can be provided by simply
linking to them in the prose near the video
element.
The video
element is a media element whose media data is ostensibly video data, possibly
with associated audio data.
The src
, preload
, autoplay
, mediagroup
, loop
, muted
, and controls
attributes are the attributes common to all media
elements.
The poster
attribute gives the
address of an image file that the user agent can show while no
video data is available. The attribute, if present, must contain a
valid
non-empty URL potentially surrounded by spaces.
The image given by the poster
attribute, the poster
frame, is intended to be a representative frame of the
video (typically one of the first non-blank frames) that gives the
user an idea of what the video is like.
videoWidth
videoHeight
These attributes return the intrinsic dimensions of the video, or zero if the dimensions are not known.
The video
element supports dimension attributes.
This example shows how to detect when a video has failed to play correctly:
<script> function failed(e) { // video playback failed - show a message saying why switch (e.target.error.code) { case e.target.error.MEDIA_ERR_ABORTED: alert('You aborted the video playback.'); break; case e.target.error.MEDIA_ERR_NETWORK: alert('A network error caused the video download to fail part-way.'); break; case e.target.error.MEDIA_ERR_DECODE: alert('The video playback was aborted due to a corruption problem or because the video used features your browser did not support.'); break; case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED: alert('The video could not be loaded, either because the server or network failed or because the format is not supported.'); break; default: alert('An unknown error occurred.'); break; } } </script> <p><video src="tgif.vid" autoplay controls onerror="failed(event)"></video></p> <p><a href="tgif.vid">Download the video file</a>.</p>