English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML tag list

HTML Audio/Video DOM addTextTrack() method

HTML Audio/How to use the video DOM addTextTrack() method, online instance demonstration of using HTML audio/Detailed information about the video DOM addTextTrack() method, browser compatibility, syntax definition, and its attribute values, etc.

 HTML Audio/Video DOM Reference Manual

Online Example

Add a new text track to the video:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML Audio/Video addTextTrack() method usage-Basic Tutorial(oldtoolbag.com)</<title>
</<head>
<body>
<button onclick="addNewTextTrack()" type="button">Add a new text track: </button>
<br> 
<video id="video1" controls="controls">
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support HTML5 video tag.
</video>
<script>
myVid=document.getElementById("video1);
function addNewTextTrack()
{ 
  text1=myVid.addTextTrack("caption");
  text1.addCue(new TextTrackCue("Test text", 01.000, 04.000,"","","",true));
} 
</script> 
</body>
</html>
Test to see ‹/›

Definition and Usage

The addTextTrack() method creates and returns a new TextTrack object.
A new TextTrack object will be added to the audio/in the list of text tracks of the video element.

Browser Compatibility

IEFirefoxOperaChromeSafari

All mainstream browsers do not support the addTextTrack() method.

Syntax

audio|video.addTextTrack(kind,label,language)

Parameters

ValuesDescription
kindSpecifies the type of the text track.

Possible Values:

  • "subtitles"

  • "caption"

  • "descriptions"

  • "chapters"

  •  "metadata"

labelA string value, specifies the label for the text track. Used to identify the text track for the user.
languagetwo-letter language codes specify the language of the text track.
For a list of all available language codes, please refer to our Language Code Reference Manual.

Return Value

TypeDescription
TextTrack ObjectRepresents a new text track.
 HTML Audio/Video DOM Reference Manual