HTML track Tag: How to Add Subtitles to Videos

The track tag in HTML adds text tracks like subtitles and captions to media. It improves video access and helps search engines. It also supports multiple languages.

Understand the <track> Tag in HTML

The <track> tag adds extra text content to a media file. It works only inside <video> or <audio>. You can use it for subtitles or captions. It does not show on its own. It only supports media with the right player or browser.

This is the basic tag:

<track src="file.vtt" kind="subtitles" srclang="en" label="English" default>

Each part tells the browser what kind of track it is and what language it uses. Also, it tells what the track to load by default.

So, how does it support <video> and <audio> Tags?

You use the <track> tag inside a <video> or <audio> element. It does not work on its own. The browser reads it and shows subtitles or captions. It also reads metadata while the media plays.

Users can turn text tracks on or off if the player supports it.

Here is how each attribute works:

  • src: sets the file path to the track. It must be a .vtt file. Required.
  • kind: tells the browser what kind of track it is. Common values include subtitles, captions, descriptions, chapters, and metadata. Optional but needed.
  • srclang: shows the track language. Use language codes like en, fr, or es. Required when kind="subtitles".
  • label: gives the track a name. This name appears in the video player.
  • default: loads this track first unless the user chooses another.

So, why should you use the <track> tag?

Here is a list that shows you the common use cases of the <track> tag:

  • Add subtitles for users who do not speak the audio language.
  • Show captions for users who are deaf.
  • Describe scenes with sound for blind users.
  • Mark chapters so users can jump to sections in long videos.
  • Add extra metadata like keywords or tags for custom player tools.

Now that you know where to use it, let us look at the different types of tracks.

Types of Tracks

The kind attribute tells the browser what type of track you added. You choose from the following:

  • subtitles: show spoken words in text. Good for users who speak other languages.
  • captions: show both spoken words and sound effects. Help users who cannot hear the audio.
  • descriptions: explain what happens on screen with text. Used for users with low vision.
  • chapters: break videos into named parts. This allows you to skip parts you interested.
  • metadata: stores extra data for scripts or plugins. It does not show to the user.

Each kind has a clear purpose. You choose based on what your media needs.

How to Create .vtt Files for <track> Tag in HTML

WebVTT files use simple text. You set the time and the text to show. Here is a sample format:

00:00:01.000 --> 00:00:04.000
Welcome to our video guide.

00:00:05.000 --> 00:00:08.000
In this part, you will learn the basics.

Save this as file.vtt and link it in the src attribute.

You can use these tools in it:

  • Notepad or VS Code to write the file
  • VTT Creator (web-based editors)
  • W3C Validator to check syntax
  • Subtitle Edit for advanced control

You must save the file as UTF-8 without BOM. Some editors offer this option with save.

Examples of <track> Tag in HTML

English Subtitles for a Video:

<video controls width="400">
  <source src="lesson.mp4" type="video/mp4">
  <track src="english.vtt" kind="subtitles" srclang="en" label="English" default>
</video>

This example shows a video with English subtitles. The track loads by default. The user can turn subtitles on or off. This helps non-native English speakers.

Captions and Subtitles with Language Switch:

<video controls width="400">
  <source src="interview.mp4" type="video/mp4">
  <track src="english_captions.vtt" kind="captions" srclang="en" label="English" default>
  <track src="french_subs.vtt" kind="subtitles" srclang="fr" label="Français">
</video>

This example includes both captions and subtitles. English captions load first. French users can switch to French subtitles.

Metadata Track for Chapter Navigation:

<video controls width="400">
  <source src="documentary.mp4" type="video/mp4">
  <track src="chapters.vtt" kind="chapters" srclang="en" label="Chapters">
</video>

This uses the chapters kind. Each entry in the VTT file marks a section of the video. A media player can show a list of chapters to help users jump to key parts.

Descriptive Text for Visually Impaired Users:

<video controls width="400">
  <source src="nature.mp4" type="video/mp4">
  <track src="descriptions.vtt" kind="descriptions" srclang="en" label="Audio Descriptions">
</video>

This track type adds scene descriptions. It helps blind or low-vision users understand what happens on screen. The browser or screen reader can read the text aloud if supported.

Wrapping Up

In this article, you learned what the <track> tag does, how to use it. Also, you learned how to create .vtt files. You also saw the types of tracks and where they fit best.

Here is a quick recap:

  • The <track> tag adds extra text tracks to media.
  • You use it inside <video> or <audio> tags.
  • You choose the track type with the kind attribute.
  • Subtitles and chapters help make content better for all users.
  • Use .vtt files to store your text tracks.

FAQs

What is the purpose of the <track> tag in HTML?

The <track> tag in HTML is used to specify text tracks for <video> and <audio> elements. It allows developers to add subtitles, captions, descriptions, chapters, or metadata to media content, improving accessibility and user experience.

How do you use the <track> tag to add subtitles to a video?

To add subtitles using the &amp;lt;track&amp;gt; tag, include it inside a &amp;lt;video&amp;gt; element. Example:

<video controls>
  <source src="movie.mp4" type="video/mp4">
  <track src="subtitles.vtt" kind="subtitles" srclang="en" label="English" default>
</video>
This loads English subtitles from the "subtitles.vtt" file.

What are the key attributes of the HTML <track> tag?

The most common attributes of the <track> tag include:
  • src – URL of the track file (.vtt)
  • kind – Type of track (e.g., "subtitles", "captions")
  • srclang – Language of the track (e.g., "en")
  • label – User-readable title
  • default – Indicates the default track to display

Can the <track> tag be used with the <audio> tag?

Yes, the <track> tag can technically be used with the <audio> tag to provide captions or metadata. However, support across browsers is limited, and subtitles with audio content often require custom JavaScript solutions for full compatibility.

Similar Reads

How to Create HTML Nested Lists with Examples

In this article, you will learn how the browsers read nested lists in HTML and how to use them with…

HTML template Tag: How it Works with Examples

The HTML <template> tag lets you store HTML content that won’t show up right away. JavaScript can pull it in…

HTML figure Tag: Responsive Design & Media Elements

The HTML figure tag links media with a caption. Use it to group an image, diagram, code block, or video…

HTML time Tag: Representing Dates and Times

The HTML time Tag marks time values in a document. Use it to show dates or times that machines and…

HTML iframe Tag: How to Embed Content with Examples

The iframe tag embeds another HTML page inside the current page. It loads content from a separate source. Understand the…

HTML base Tag: How to Set a Base URL for Links and Resources

Use the <base> tag in HTML to set a single base URL or target for all relative links and resources…

The canvas Tag in HTML: How to Draw Graphics with Examples

The HTML canvas tag draws shapes and images. It also helps you draw text with code. It gives control over…

HTML title Attribute: How it Works with Examples

The HTML title attribute adds extra info to any element. You can use it to show tooltips on hover. What…

HTML title Tag: How to Set Web Page Titles

The title tag in HTML shows the page name in the browser tab and helps search engines know the topic.…

HTML samp Tag: How to Show Sample Program Output

The HTML samp tag shows the result of a computer program or command. It helps readers know which text came…

Previous Article

HTML svg Tag: Scalable Vector Graphics for the Web

Next Article

The canvas Tag in HTML: How to Draw Graphics with Examples

Write a Comment

Leave a Comment

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


Subscribe to Get Updates

Get the latest updates on Coding, Database, and Algorithms straight to your inbox.
No spam. Unsubscribe anytime.