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/icon.png">
  <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

Required Attributes

NONE

Optional Attributes

autoplay - specifies the video will play as soon as it is ready.


<!-- Valid values are an empty string or autofocus -->
<video autoplay>Video content here</video>
<video autoplay="autoplay">Video content here</video>

controls - specifies whether to display video controls such as stop/play/pause.


<!-- Valid values are an empty string or autofocus -->
<video controls>Video content here</video>
<video controls="controls">Video content here</video>

height specifies the height of the image in pixels.


<video height="200">Video content here</video>

loop - specifies whether to continue playing the video in an endless loop.


<!-- Valid values are an empty string or loop -->
<video loop>Video content here</video>
<video loop="loop">Video content here</video>

muted - specifies whether the video is muted.


<!-- Valid values are an empty string or muted -->
<video muted>Video content here</video>
<video muted="muted">Video content here</video>

poster specifies the URL location of an image to display while video is loading.


<!-- Must be a valid URL of an image -->
<video src="../images/chickenpiesmall.jpg">Video content here</video>

preload specifies if the video should be prelodaed and if so, how.


<!-- Valid values are auto, none and metadata,  -->
<video preload="auto">Video content here</video>

src specifies the URL location of a video file.


<!-- Required when source used in video -->
<video src="https://server2client.com/pages/ball.avi">Video content here</video>

width specifies the width of the image in pixels.


<video width="200">Video content here</video>

Global Attributes

Common

class - specifies a classname for the element allowing you to apply the style of the predefined class to the content.


<video class="classname">Video content here</video>

id - specifies a unique id for the element allowing you to apply the style of the predefined id to the content.


<video id="idname">Video content here</video>

style - specifies an inline style for the element allowing you to apply the style to the content.


<video style="color:red;text-align:left">Video content here</video>

title - specifies extra information about the content.


<video title="information about the content">Video content here</video>

Keyboard

accesskey - specifies a keyboard shortcut to associate with the element.


<video accesskey="aKeyValue">Video content here</video>

tabindex - specifies a tab order for the element.


<video tabindex="someNumber">Video content here</video>

Language

dir - specifies the directional flow of the content.


<video dir="ltr">Video content here</video>   <!-- The text will flow from left to right -->
<video dir="rtl">Video content here</video>   <!-- The text will flow from right to left -->

lang - specifies a language code for the content of the element.


<video lang="en">Video content here</video>

spellcheck - specifies whether the element is to have its spelling checked.


<!-- Valid values are true and  false - default is inherited / browser specific. -->
<video spellcheck="true">Video content here</video>

translate - specifies whether the content of the element can be translated.


<!-- Valid values are yes and  no - default is yes. -->
<video translate="no">Video content here</video> 

Miscellaneous

contenteditable - specifies whether the content of the element is editable.


<!-- Valid values are true and  false - default is inherited. -->
<video contenteditable="false">Video content here</video> 

draggable - specifies whether the the element is draggable.

Only text selections, images, and links can be dragged.


<!-- Valid values are true and  false - default is browser specific. -->
<video draggable="true">Video content here</video>

hidden - specifies whether the element is not yet, or no longer, relevant.


<!-- Valid values are an empty string or hidden -->
<video hidden>Video content here</video> 
<video hidden="hidden">Video content here</video> 

Event Attributes

Document

onabort - The JavaScript code to be run on abort.


<video onabort="go()">Video content here</video>   <!-- Executes the go() function -->

onerror - The JavaScript code to be run when an error occurs when the file is being loaded.


<video onerror="go()">Video content here</video>   <!-- Executes the go() function -->

onload - The JavaScript code to be run when the document is loaded.


<video onload="go()">Video content here</video>   <!-- Executes the go() function -->

onresize - The JavaScript code to be run when the browser window is resized.


<video onresize="go()">Video content here</video>   <!-- Executes the go() function -->

onscroll - The JavaScript code to be run when the scrollbar of an element is being scrolled.


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

onunload - The JavaScript code to be run once a page has unloaded or the browser window has been closed.


<video onunload="go()">Video content here</video>   <!-- Executes the go() function -->

Document Element

oncopy - The JavaScript code to be run when the user copies the content of an element.


<video oncopy="go()">Video content here</video>   <!-- Executes the go() function -->

oncut - The JavaScript code to be run when the user cuts the content of an element.


<video oncut="go()">Video content here</video>   <!-- Executes the go() function -->

onpaste - The JavaScript code to be run when the user pastes some content into an element.


<video onpaste="go()">Video content here</video>   <!-- Executes the go() function -->

Drag and Drop

ondrag - The JavaScript code to be run when an element is dragged.


<video ondrag="go()">Video content here</video>   <!-- Executes the go() function -->

ondragend - The JavaScript code to be run when an element has stopped being dragged.


<video ondragend="go()">Video content here</video>   <!-- Executes the go() function -->

ondragenter - The JavaScript code to be run when an element has been dragged to a valid drop target.


<video ondragenter="go()">Video content here</video>   <!-- Executes the go() function -->

ondragleave - The JavaScript code to be run when an element leaves a valid drop target.


<video ondragleave="go()">Video content here</video>   <!-- Executes the go() function -->

ondragover - The JavaScript code to be run when an element is being dragged over a valid drop target.


<video ondragover="go()">Video content here</video>   <!-- Executes the go() function -->

ondragstart - The JavaScript code to be run at the start of a drag operation.


<video ondragstart="go()">Video content here</video>   <!-- Executes the go() function -->

ondrop - The JavaScript code to be run when dragged element is being dropped.


<video ondrop="go()">Video content here</video>   <!-- Executes the go() function -->

Form

onblur - The JavaScript code to be run on abort.


<video onblur="go()">Video content here</video>   <!-- Executes the go() function -->

onchange - The JavaScript code to be run when object changed and attempt to leave field.


<video onchange="go()">Video content here</video>   <!-- Executes the go() function -->

oncontextmenu - The JavaScript code to be run when a context menu is triggered.


<video oncontextmenu="go()">Video content here</video>   <!-- Executes the go() function -->

onfocus - The JavaScript code to be run when the element gets focus.


<video onfocus="go()">Video content here</video>   <!-- Executes the go() function -->

oninput - The JavaScript code to be run when an element gets user input.


<video oninput="go()">Video content here</video>   <!-- Executes the go() function -->

oninvalid - The JavaScript code to be run when an element is invalid.


<video oninvalid="go()">Video content here</video>   <!-- Executes the go() function -->

onreset - The JavaScript code to be run when the reset button of a form is clicked.


<video onreset="go()">Video content here</video>   <!-- Executes the go() function -->

onselect - The JavaScript code to be run when some or all of the contents of an object are selected.


<video onselect="go()">Video content here</video>   <!-- Executes the go() function -->

onsubmit - The JavaScript code to be run when a form is submitted.


<video onsubmit="go()">Video content here</video>   <!-- Executes the go() function -->

Keyboard

onkeydown - The JavaScript code to be run when an element is in focus and keyboard key is pressed.


<video onkeydown="go()">Video content here</video>   <!-- Executes the go() function -->

onkeypress - The JavaScript code to be run when an element is in focus and keyboard key is pressed down and released.


<video onkeypress="go()">Video content here</video>   <!-- Executes the go() function -->

onkeyup - The JavaScript code to be run when an element is in focus and keyboard key is released.


<video onkeyup="go()">Video content here</video>   <!-- Executes the go() function -->

Media

oncanplay - The JavaScript code to be run when a file has buffered enough so it is ready to start playing.


<video oncanplay="go()">Video content here</video>   <!-- Executes the go() function -->

oncanplaythrough - The JavaScript code to be run when a file can be played all the way to the end without further need of buffering.


<video oncanplaythrough="go()">Video content here</video>   <!-- Executes the go() function -->

oncuechange - The JavaScript code to be run when the cue changes when using the track element.


<video oncuechange="go()">Video content here</video>   <!-- Executes the go() function -->

ondurationchange - The JavaScript code to be run when the length of the media is changed.


<video ondurationchange="go()">Video content here</video>   <!-- Executes the go() function -->

onemptied - The JavaScript code to be run when a media resource element suddenly becomes empty, usually due to an error.


<video onemptied="go()">Video content here</video>   <!-- Executes the go() function -->

onended - The JavaScript code to be run when the media has reach the end.


<video onended="go()">Video content here</video>   <!-- Executes the go() function -->

onloadeddata - The JavaScript code to be run when media data is loaded and playback can start.


<video onloadeddata="go()">Video content here</video>   <!-- Executes the go() function -->

onloadedmetadata - The JavaScript code to be run when metadata has been loaded.


<video onloadedmetadata="go()">Video content here</video>   <!-- Executes the go() function -->

onloadstart - The JavaScript code to be run when the media resource has started loading.


<video onloadstart="go()">Video content here</video>   <!-- Executes the go() function -->

onpause - The JavaScript code to be run when the media resource has been paused.


<video onpause="go()">Video content here</video>   <!-- Executes the go() function -->

onplay - The JavaScript code to be run when the media resource starts playback.


<video onplay="go()">Video content here</video>   <!-- Executes the go() function -->

onplaying - The JavaScript code to be run when playback has already begun.


<video onplaying="go()">Video content here</video>   <!-- Executes the go() function -->

onprogress - The JavaScript code to be run when the browser is fetching the media data.


<video onprogress="go()">Video content here</video>   <!-- Executes the go() function -->

onratechange - The JavaScript code to be run when the playback rate changes.


<video onratechange="go()">Video content here</video>   <!-- Executes the go() function -->

onseeked - The JavaScript code to be run when the seeking attribute is set to false indicating that seeking has finished.


<video onseeked="go()">Video content here</video>   <!-- Executes the go() function -->

onseeking - The JavaScript code to be run hen the seeking attribute is set to true indicating that seeking is currently active.


<video onseeking="go()">Video content here</video>   <!-- Executes the go() function -->

onstalled - The JavaScript code to be run when the browser is unable to continue fetching media data.


<video onstalled="go()">Video content here</video>   <!-- Executes the go() function -->

onsuspend - The JavaScript code to be run when media data has stopped before being completely loaded.


<video onsuspend="go()">Video content here</video>   <!-- Executes the go() function -->

ontimeupdate - The JavaScript code to be run when the media resources current playback position has changed.


<video ontimeupdate="go()">Video content here</video>   <!-- Executes the go() function -->

onvolumechange - The JavaScript code to be run when the volume has changed or been muted.


<video onvolumechange="go()">Video content here</video>   <!-- Executes the go() function -->

onwaiting - The JavaScript code to be run when the media resource has paused but is expected to resume.


<video onwaiting="go()">Video content here</video>   <!-- Executes the go() function -->

Mouse

onclick - The JavaScript code to be run when a mouse is clicked on the element.


<video onclick="go()">Video content here</video>   <!-- Executes the go() function -->

ondblclick - The JavaScript code to be run when a mouse is double clicked on the element.


<video ondblclick="go()">Video content here</video>   <!-- Executes the go() function -->

onmousedown - The JavaScript code to be run when the mouse button is pressed down while the cursor is over the element.


<video onmousedown="go()">Video content here</video>   <!-- Executes the go() function -->

onmousemove - The JavaScript code to be run when the mouse button is moved.


<video onmousemove="go()">Video content here</video>   <!-- Executes the go() function -->

onmouseout - The JavaScript code to be run when the mouse cursor moves off an element.


<video onmouseout="go()">Video content here</video>   <!-- Executes the go() function -->

onmouseover - The JavaScript code to be run when the mouse cursor moves over an element.


<video onmouseover="go()">Video content here</video>   <!-- Executes the go() function -->

onmouseup - The JavaScript code to be run when the mouse button is released while the cursor is over the element.


<video onmouseup="go()">Video content here</video>   <!-- Executes the go() function -->

onwheel - The JavaScript code to be run when the mouse wheel rolls up or down over an element.


<video onwheel="go()">Video content here</video>   <!-- Executes the go() function -->

Window

NONE

go to home page Homepage go to top of page Top