HTML<track> tag

HTML <track> tag is used to define time-based text tracks for a media file. The <track> tag must use as child element of <audio> and <video> elements.

The <track> tag is used to add subtitle, caption, or any other form of text which displayed when a media file plays.

HTML <track> is new tag in HTML5.

Syntax

  1. <track src=” “ kind=” “ srclang=” “ label=” “>  

Following are some specifications about the HTML <track> tag

DisplayNone
Start tag/End tagOnly start tag(End tag forbidden)
UsageHTML media

Example

  1.  <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <title>HTML track Tag</title>  
  5. </head>  
  6. <body>  
  7.  <h2>Example of track tag</h2>  
  8.  <video controls=“controls”>  
  9.      <source src=“flower.mp4” type=“video/mp4”>  
  10.     <track src=“flower.vtt” kind=“subtitles” srclang=“en” label=“English”>  
  11.     Sorry!Your browser does not support the track  
  12.  </video>  
  13. </body>  
  14. </html>  
Test it Now

In the above example, we have used flower.vtt file to add subtitle in the video file. Following is the flower.vtt file:

HTML track tag

How to create WEBVTT file:

Following are some basic steps to create WEBVTT file for <track> tag:

  1. Open text editor in your PC such as Notepad
  2. Write WEBVTT as the first line in the editor
  3. Leave a blank line
  4. Specify the time duration in the proper format (you can also provide numbering and add CSS).
  5. Enter and write your text which you want to add a subtitle or caption, and repeat step 3 to 5 until you finish it.
  6. Save it using .vtt extension.

Now your WEBVTT file is ready to use.

Attribute:

Tag-specific attributes:

AttributeValueDescription
defaultdefaultIt specifies that the track should be enabled unless the user?s preferences indicate that another track is more important.
kindcaptionschaptersdescriptionsmetadatasubtitlesIt specifies that which type of text track you want to add.
labeltextIt specifies the title of the text track.
srcURLIt defines the URL of the track file.
srclanglanguage_codeIt defines the language of the track text content, such as English, Germany, etc.

Global attribute:

The <track> tag supports the Global attributes in HTML.

Event attribute:

The <track> tag supports the Event attributes in HTML.

Supporting Browsers

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<track>YesYesYesYesYes


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *