HTML <video> tagS2C Home   « HTML <video> tag

Definition

The <video> tag is used to embed video content into a HTML document.

The <video> tag can be used in conbination with the <source> to provide a list of videos where the first valid one is played, or standalone.

The <video> tag was introduced in HTML5.

Examples


<video controls autoplay width="200" height="200" poster="../images/fbimg.JPG">
  <source src="../pages/HD0405.mp4" type="video/ogg">
  <source src="../pages/HD0405.mp4" type="video/mp4">
  Sorry, your browser doesn't support embedded videos.
</video>
<video controls src="../pages/HD0405.mp4" width="200" height="200">
  Sorry, your browser doesn't support embedded videos.
</video>

Video courtesy of MovieTOOLS

Attributes

The following attributes can be used with the <video> tag.


<video> Specific Attributes
Attribute Value Description Example
autoplayempty string or autoplaySpecifies the video will play as soon as it is ready.

<video src="../../pages/HD0405.mp4"
       autoplay>Video content here</video>
<video src="../../pages/HD0405.mp4"
       autoplay="autoplay">Video content here</video>
controlsempty string or controlsSpecifies whether to display video controls such as stop/play/pause.

<video src="../../pages/HD0405.mp4"
       controls>Video content here</video>
<video src="../../pages/HD0405.mp4"
       controls="controls">Video content here</video>
heightdatetimeSpecifies the height of the image in pixels.

<video src="../../pages/HD0405.mp4"
       height="200">Video content here</video>
loopempty string or loopSpecifies whether to continue playing the video in an endless loop.

<video src="../../pages/HD0405.mp4"
       loop>Video content here</video>
<video src="../../pages/HD0405.mp4"
       loop="loop">Video content here</video>
mutedempty string or mutedSpecifies whether the video is muted.

<video src="../../pages/HD0405.mp4"
       muted>Video content here</video>
<video  src="../../pages/HD0405.mp4"
       muted="muted">Video content here</video>
posterurlSpecifies the URL location of an image to display while video is loading.

Must be a valid URL of an image.

<video src="../../pages/HD0405.mp4"
     poster="../../images/fbimg.JPG">Video content here</video>
preloadauto, none and metadataSpecifies if the video should be prelodaed and if so, how.

<video src="../../pages/HD0405.mp4"
       preload="auto">Video content here</video>
srcurlSpecifies the URL location of a video file.

<video src="../../pages/HD0405.mp4">Video content here</video>
widthdatetimeSpecifies the width of the image in pixels.

<video src="../../pages/HD0405.mp4"
       width="200">Video content here</video>
<video> Global Attributes
Attribute Description Example
Common
classSpecifies a classname for the element allowing you to apply the style of the predefined class to the content.

<video class="name">Video content here</video>
idSpecifies a unique id for the element allowing you to apply the style of the predefined id to the content.

<video id="name">Video content here</video>
styleSpecifies an inline style for the element allowing you to apply the style to the contentt.

<video style="color:red;">Video content here</video>
titleSpecifies an inline style for the element allowing you to apply the style to the content.

<video title="Content info">Video content here</video>
Keyboard
accesskeySpecifies a keyboard shortcut to associate with the element.

<video accesskey="a">Video content here</video>
tabindexSpecifies a tab order for the element.

<video tabindex="1">Video content here</video>
Language
dirSpecifies the directional flow of the content.

<!-- The text will flow from left to right -->
<video dir="ltr">Video content here</video>
<!-- The text will flow from right to left -->
<video dir="rtl">Video content here</video>
langSpecifies a language code for the content of the element.

<video lang="en">Video content here</video>
spellcheckSpecifies an inline style for the element allowing you to apply the style to the contentt.

<!-- Valid values true and false. -->
<!-- Default inherited / browser specific. -->
<video spellcheck="true">Video content here</video> 
translateSpecifies an inline style for the element allowing you to apply the style to the content.

<!-- Valid values yes and no. -->
<!-- Default yes. -->
<video translate="no">Video content here</video> 
Miscellaneous
contenteditableSpecifies whether the content of the element is editable.

<!-- Valid values true and false. -->
<!-- Default inherited. -->
<video contenteditable="true">Video content here</video> 
draggableSpecifies whether the element is draggable.

<!-- Valid values true and false. -->
<!-- Default browser specific. -->
<video draggable="true">Video content here</video>
hiddenSpecifies whether the element is not yet, or no longer, relevant.

<!-- Valid values an empty string or hidden -->
<video hidden>Video content here</video> 
<video hidden="hidden">Video content here</video> 
<video> Event Attributes
Attribute Description Example
Document Element
oncopyThe script to be run when the user copies the content of an element.

 <!-- Executes go() function -->
<video oncopy="go()">Video content here</video> 
oncutThe script to be run when the user cuts the content of an element.

 <!-- Executes go() function -->
<video oncut="go()">Video content here</video>
onpasteThe script to be run when the user pastes some content into an element.

 <!-- Executes go() function -->
<video onpaste="go()">Video content here</video>
Drag and Drop
ondragThe script to be run when an element is dragged.

 <!-- Executes go() function -->
<video ondrag="go()">Video content here</video>
ondragendThe script to be run when an element has stopped being dragged.

 <!-- Executes go() function -->
<video ondragend="go()">Video content here</video>
ondragenterThe script to be run when an element has been dragged to a valid drop target.

 <!-- Executes go() function -->
<video ondragenter="go()">Video content here</video>
ondragleaveThe script to be run when an element leaves a valid drop target.

 <!-- Executes go() function -->
<video ondragleave="go()">Video content here</video>
ondragoverThe script to be run when an element is being dragged over a valid drop target.

 <!-- Executes go() function -->
<video ondragover="go()">Video content here</video>
ondragstartThe script to be run at the start of a drag operation.

 <!-- Executes go() function -->
<video ondragstart="go()">Video content here</video>
ondropThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<video ondrop="go()">Video content here</video>
Form
onblurThe script to be run when the element loses focus.

 <!-- Executes go() function -->
<video onblur="go()">Video content here</video>
onchangeThe script to be run when object changed and attempt to leave field.

 <!-- Executes go() function -->
<video onchange="go()">Video content here</video>
oncontextmenuThe script to be run when a context menu is triggered.

 <!-- Executes go() function -->
<video oncontextmenu="go()">Video content here</video>
onfocusThe script to be run when the element gets focus.

 <!-- Executes go() function -->
<video onfocus="go()">Video content here</video>
oninputThe script to be run when an element gets user input.

 <!-- Executes go() function -->
<video oninput="go()">Video content here</video>
oninvalidThe script to be run when an element is invalid.

 <!-- Executes go() function -->
<video oninvalid="go()">Video content here</video>
onresetThe script to be run when a dragged element is being dropped.

 <!-- Executes go() function -->
<video onreset="go()">Video content here</video>
onselectThe script to be run when some or all of the contents of an object are selected.

 <!-- Executes go() function -->
<video onselect="go()">Video content here</video>
onsubmitThe script to be run when a form is submitted.

 <!-- Executes go() function -->
<video onsubmit="go()">Video content here</video>
Keyboard
onkeydownThe script to be run when an element is in focus and keyboard key is pressed down.

 <!-- Executes go() function -->
<video onkeydown="go()">Video content here</video>
onkeypressThe script to be run when an element is in focus and keyboard key is pressed down and released.

 <!-- Executes go() function -->
<video onkeypress="go()">Video content here</video>
onkeyupThe script to be run when an element is in focus and keyboard key is released.

 <!-- Executes go() function -->
<video onkeyup="go()">Video content here</video>
Media
onabortThe script code to be run on abort.

 <!-- Executes go() function -->
<video onabort="go()">Video content here</video>
oncanplayThe script to be run when a file has buffered enough so it is ready to start playing.

 <!-- Executes go() function -->
<video oncanplay="go()">Video content here</video>
oncanplaythroughThe script to be run when a file can be played all the way to the end without further need of buffering.

 <!-- Executes go() function -->
<video oncanplaythrough="go()">Video content here</video>
oncuechangeThe script to be run when the cue changes when using the track element.

 <!-- Executes go() function -->
<video oncuechange="go()">Video content here</video>
ondurationchangeThe script to be run when the length of the media is changed.

 <!-- Executes go() function -->
<video ondurationchange="go()">Video content here</video>
onemptiedThe script to be run when a media resource element suddenly becomes empty, usually due to an error.

 <!-- Executes go() function -->
<video onemptied="go()">Video content here</video>
onendedThe script to be run when the media has reach the end.

 <!-- Executes go() function -->
<video onended="go()">Video content here</video>
onloadeddataThe script to be run when media data is loaded and playback can start.

 <!-- Executes go() function -->
<video onloadeddata="go()">Video content here</video>
onloadedmetadataThe script to be run when metadata has been loaded.

 <!-- Executes go() function -->
<video onloadedmetadata="go()">Video content here</video>
onloadstartThe script to be run whenthe media resource has started loading.

 <!-- Executes go() function -->
<video onloadstart="go()">Video content here</video>
onpauseThe script to be run when the media resource has been paused.

 <!-- Executes go() function -->
<video onpause="go()">Video content here</video>
onplayThe script to be run when the media resource starts playback.

 <!-- Executes go() function -->
<video onplay="go()">Video content here</video>
onplayingThe script to be run when when playback has already begun.

 <!-- Executes go() function -->
<video onplaying="go()">Video content here</video>
onprogressThe script to be run when the browser is fetching the media data.

 <!-- Executes go() function -->
<video onprogress="go()">Video content here</video>
onratechangeThe script to be run when the playback rate changes.

 <!-- Executes go() function -->
<video onratechange="go()">Video content here</video>
onseekedThe script to be run when the seeking attribute is set to false indicating that seeking has finished.

 <!-- Executes go() function -->
<video onseeked="go()">Video content here</video>
onseekingThe script to be run when the seeking attribute is set to true indicating that seeking is currently active.

 <!-- Executes go() function -->
<video onseeking="go()">Video content here</video>
onstalledThe script to be run when the browser is unable to continue fetching media data.

 <!-- Executes go() function -->
<video onstalled="go()">Video content here</video>
onsuspendThe script to be run when media data has stopped before being completely loaded.

 <!-- Executes go() function -->
<video onsuspend="go()">Video content here</video>
ontimeupdateThe script to be run when the media resources current playback position has changed.

 <!-- Executes go() function -->
<video ontimeupdate="go()">Video content here</video>
onvolumechangeThe script to be run when the volume has changed or been muted.

 <!-- Executes go() function -->
<video onvolumechange="go()">Video content here</video>
onwaitingThe script to be run when the media resource has paused but is expected to resume.

 <!-- Executes go() function -->
<video onwaiting="go()">Video content here</video>
Mouse
onclickThe script to be run when when a mouse is clicked on an element.

 <!-- Executes go() function -->
<video onclick="go()">Video content here</video>
ondblclickThe script to be run when a mouse is double clicked on an element.

 <!-- Executes go() function -->
<video ondblclick="go()">Video content here</video>
onmousedownThe script to be run when he mouse button is pressed down while the cursor is over an element.

 <!-- Executes go() function -->
<video onmousedown="go()">Video content here</video>
onmousemoveThe script to be run when the mouse button is moved.

 <!-- Executes go() function -->
<video onmousemove="go()">Video content here</video>
onmouseoutThe script to be run when the mouse cursor moves off an element.

 <!-- Executes go() function -->
<video onmouseout="go()">Video content here</video>
onmouseoverThe script to be run when the mouse cursor moves over an element.

 <!-- Executes go() function -->
<video onmouseover="go()">Video content here</video>
onmouseupThe script to be run when the mouse button is released while the cursor is over the element.

 <!-- Executes go() function -->
<video onmouseup="go()">Video content here</video>
onwheelThe script to be run when the mouse wheel rolls up or down over an element.

 <!-- Executes go() function -->
<video onwheel="go()">Video content here</video>
Scroll
onscrollThe script code to be run when the scrollbar of an element is being scrolled.

 <!-- Executes go() function -->
<video onscroll="go()">Video content here</video> 
Window - NONE

Relevant HTML Tutorials

HTML Advanced - Audio & Video