Attributes
Attributes can be added to an HTML element to provide more information about how the element should appear or behave.
There are 3 kinds of attributes that you can add to your HTML tags: Element-specific, global, and event handler content attributes.
The element accepts the following attributes.
Element-Specific Attributes
This table shows the attributes that are specific to the tag/element.
Attribute | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
kind | Specifies the kind of text track. This attribute is an enumerated attribute.
The possible values for the «kind» attribute are:
|
||||||||||||
src | Specifies the URL of the text track data. Required attribute. | ||||||||||||
srclang | Specifies the language of the text track. The value must be a valid BCP 47 language tag. This attribute is required if the element’s kind attribute is «subtitles». | ||||||||||||
label | Provides a user-readable title for the track. | ||||||||||||
default | Specifies that the track is to be enabled if the user’s preferences do not indicate that another track would be more appropriate. There must not be more than one track element with the same parent node with the default attribute specified. |
Global Attributes
The following attributes are standard across all HTML5 elements. Therefore, you can use these attributes with the tag , as well as with all other HTML tags.
- accesskey
- class
- contenteditable
- contextmenu
- dir
- draggable
- dropzone
- hidden
- id
- inert
- itemid
- itemprop
- itemref
- itemscope
- itemtype
- lang
- spellcheck
- style
- tabindex
- title
- translate
For a full explanation of these attributes, see HTML 5 global attributes.
Event Handler Content Attributes
Event handler content attributes enable you to invoke a script from within your HTML. The script is invoked when a certain «event» occurs. Each event handler content attribute deals with a different event.
Below are the standard HTML5 event handler content attributes.
Again, you can use any of these with the element, as well as any other HTML5 element.
- onabort
- oncancel
- onblur
- oncanplay
- oncanplaythrough
- onchange
- onclick
- oncontextmenu
- ondblclick
- ondrag
- ondragend
- ondragenter
- ondragexit
- ondragleave
- ondragover
- ondragstart
- ondrop
- ondurationchange
- onemptied
- onended
- onerror
- onfocus
- onformchange
- onforminput
- oninput
- oninvalid
- onkeydown
- onkeypress
- onkeyup
- onload
- onloadeddata
- onloadedmetadata
- onloadstart
- onmousedown
- onmousemove
- onmouseout
- onmouseover
- onmouseup
- onmousewheel
- onpause
- onplay
- onplaying
- onprogress
- onratechange
- onreadystatechange
- onscroll
- onseeked
- onseeking
- onselect
- onshow
- onstalled
- onsubmit
- onsuspend
- ontimeupdate
- onvolumechange
- onwaiting
For a full explanation of these attributes, see HTML 5 event handler content attributes.
Example
In this example, the element is used to provide subtitles in English.
The above example uses a file called to present subtitles.
Here are the contents of the file:
WEBVTT
1
00:00:01.000 —> 00:00:05.000
This is the contents of the
countdown_en.vtt file
2
00:00:05.000 —> 00:00:10.000
The countdown_en.vtt file
was specified using
the ‘track’ element
3
00:00:10.000 —> 00:00:16.000
We are using the ‘track’ element
to provide subtitles for
the video
The file simply specifies which text to display at which parts of the video. To add more subtitles, simply add more text and specify the appropriate points in the video that they should be displayed.
Syntax
The tag is written as (no end tag). The attribute is a required attribute that provides the URL of the text track.
You can use the (optional) attribute to specify the kind of text track. The attribute must be present if the attribute is in the state. Note that, if you omit the attribute, it defaults to , so you will need to provide a attribute in this case.
You can also include the (optional) attribute to provide a user-visible label.
The tag must be nested inside a media element (i.e. either or ).
Like this:
<video src=»video.ogg» controls>
<track src=»text-track.vtt» kind=»subtitles» srclang=»en» label=»English»>
</video>
Template
Here’s a template for the tag with all available attributes for the tag (based on HTML5). These are grouped into attribute types, each type separated by a space. In many cases, you will probably only need one or two (if any) attributes. Simply remove the attributes you don’t need.
For more information on attributes for this tag, see HTML5 Tag.
<track
kind=»»
src=»»
srclang=»»
label=»»
default=»»
accesskey=»»
class=»»
contenteditable=»»
contextmenu=»»
dir=»»
draggable=»»
dropzone=»»
hidden=»»
id=»»
itemid=»»
itemprop=»»
itemref=»»
itemscope=»»
itemtype=»»
lang=»»
spellcheck=»»
style=»»
tabindex=»»
title=»»
translate=»»
onabort=»»
onautocomplete=»»
onautocompleteerror=»»
onblur=»»
oncancel=»»
oncanplay=»»
oncanplaythrough=»»
onchange=»»
onclick=»»
onclose=»»
oncontextmenu=»»
oncuechange=»»
ondblclick=»»
ondrag=»»
ondragend=»»
ondragenter=»»
ondragexit=»»
ondragleave=»»
ondragover=»»
ondragstart=»»
ondrop=»»
ondurationchange=»»
onemptied=»»
onended=»»
onerror=»»
onfocus=»»
oninput=»»
oninvalid=»»
onkeydown=»»
onkeypress=»»
onkeyup=»»
onload=»»
onloadeddata=»»
onloadedmetadata=»»
onloadstart=»»
onmousedown=»»
onmouseenter=»»
onmouseleave=»»
onmousemove=»»
onmouseout=»»
onmouseover=»»
onmouseup=»»
onmousewheel=»»
onpause=»»
onplay=»»
onplaying=»»
onprogress=»»
onratechange=»»
onreset=»»
onresize=»»
onscroll=»»
onseeked=»»
onseeking=»»
onselect=»»
onshow=»»
onsort=»»
onstalled=»»
onsubmit=»»
onsuspend=»»
ontimeupdate=»»
ontoggle=»»
onvolumechange=»»
onwaiting=»»
>