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

Comments in HTML: How They Work with Examples

Comments in HTML help you explain your code. You can add notes without showing anything in the browser. Understand How…

HTML Mark Tag: How to Highlight Text

The mark tag highlights text in HTML and shows that the text has relevance in the content. It adds a…

HTML vs XHTML: Key Differences Every Developer Must Know

HTML and XHTML describe web pages. You must know the differences to write code that works across browsers. This article…

HTML main Tag: How to Create a Primary Content Area

The <main> tag in HTML marks the central content of a webpage. It tells browsers and assistive technologies where the…

HTML Span Tag: Inline Container Explained

The HTML span tag acts as a simple container for inline text or other inline elements. It groups text and…

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 code Tag: How to Mark Up Code Snippets

The <code> tag in HTML shows short code, command names, or output. Use it to display text that the browser…

HTML dialog Tag: How to Create Dialog Boxes

The <dialog> tag is used to build modal popups in HTML. It shows alerts and messages without third-party scripts. Understand…

The Img Tag in HTML: How to Display Images

You need images to show products or ideas on your site. The HTML img tag places those images on the…

The Button Tag in HTML: How it Works with Examples

The HTML button tag creates interactive controls on a web page. You can use this element to trigger actions or…

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.