LEARNING OBJECTIVES โต
- Understand the legal, technical, and semantic differences between
kind="subtitles"andkind="captions"under WCAG 2.1 AA accessibility standards. - Master all 5 distinct
kindattribute values:subtitles,captions,descriptions,chapters, andmetadata. - Implement interactive, clickable video chapter navigation menus driven entirely by
kind="chapters"WebVTT tracks. - Use
kind="metadata"tracks to transmit synchronized, machine-readable JSON payloads to JavaScript runtime consumers.
๐ The Mental Model & Story (Intuitive Foundation)
Imagine watching a tense mystery movie:
- Scenario A (Subtitles): You are a hearing person watching a French movie in Paris. You hear footsteps in the dark and ominous violin music building tension. You only need the French spoken dialogue translated into English.
- Scenario B (Captions / SDH): You are a deaf or hard-of-hearing viewer. If the subtitle only displays spoken words, you will miss the critical audio cluesโthe eerie creaking floorboard upstairs, the distant gunshot, and the tense musical crescendo that signals impending danger.
+-----------------------------------------------------------------------------------+
| SUBTITLES VS CAPTIONS MENTAL MODEL |
+-----------------------------------------------------------------------------------+
| kind="subtitles" (For Hearing Viewers in Another Language): |
| "Did you hear that sound in the hallway?" |
| |
| kind="captions" (For Deaf / Hard-of-Hearing Viewers - WCAG AA Requirement): |
| [EERIE VIOLIN MUSIC BUILDS] |
| [FLOORBOARD CREAKS UPSTAIRS] |
| Detective Miller: "Did you hear that sound in the hallway?" |
| [THUNDER CRACKS OUTSIDE] |
+-----------------------------------------------------------------------------------+
The kind attribute specifies the exact semantic purpose of the timed text track. Choosing the wrong kind can violate international accessibility laws (such as ADA Title III and the European Accessibility Act) or cause assistive technologies to misinterpret the track.
Technical Deep Dive & Specifications
The 5 <track> Kinds Specification Matrix
kind Value |
Primary Target Audience | Payload Requirements | UI Render Behavior |
|---|---|---|---|
subtitles (Default) |
Users who can hear audio but do not speak the source language. | Spoken dialogue translation only. | Rendered as text overlay inside video canvas. |
captions |
Deaf or hard-of-hearing users (WCAG 2.1 AA compliance). | Dialogue + Sound Effects [EXPLOSION], Music [UPBEAT JAZZ], and Speaker IDs. |
Rendered as high-contrast overlay inside video canvas. |
descriptions |
Blind or visually impaired users. | Text description of visual actions, intended for Text-to-Speech (TTS) synthesis. | Not visually displayed; consumed by screen readers. |
chapters |
All users seeking content navigation. | Timestamps paired with section/chapter titles. | Browser or custom UI builds an interactive jump menu. |
metadata |
JavaScript client applications. | Raw JSON, XML, or sensor coordinates synchronized with video time. | Invisible to user; accessed via TextTrack.cues in JS. |
WCAG 2.1 AA Accessibility Requirements
To achieve WCAG 2.1 Success Criterion 1.2.2 (Captions - Prerecorded) and 1.2.4 (Captions - Live):
- Captions Must Be Synchronized: Text must appear at the exact moment audio is heard (within 100ms tolerance).
- Equivalent Content: All dialogue, non-speech audio cues (screams, doorbells, applause), and emotional tone in music must be transcribed.
- Speaker Identification: When multiple speakers are on screen or off screen, captions must identify each speaker by name or unique color.
Interactive Chapter Navigation with kind="chapters"
A WebVTT chapters file provides a timeline table of contents:
WEBVTT - Course Syllabus Navigation
00:00:00.000 --> 00:01:30.000
Chapter 1: Introduction to GPU Decoding
00:01:30.000 --> 00:04:15.000
Chapter 2: The MP4 moov Atom & FFmpeg
00:04:15.000 --> 00:08:00.000
Chapter 3: Custom Media Controls Engineering
When loaded via <track kind="chapters" src="chapters.vtt">, JavaScript can access the TextTrack cues and dynamically generate a clickable sidebar:
const video = document.querySelector('video');
const chapterTrack = video.textTracks[0];
// Force track to load cues into memory
chapterTrack.mode = 'hidden';
chapterTrack.oncuechange = () => {
const activeCue = chapterTrack.activeCues[0];
if (activeCue) {
highlightActiveChapter(activeCue.text);
}
};
Machine-Readable Data Streams with kind="metadata"
You can embed structured JSON inside WebVTT cues for interactive e-commerce, interactive quizzes, or sports analytics:
WEBVTT - E-Commerce Synchronized Overlay
00:00:10.000 --> 00:00:25.000
{ "productId": "sku_982", "name": "Wireless Noise-Canceling Headphones", "price": "$199.99", "url": "/shop/sku-982" }
When oncuechange fires, JavaScript parses JSON.parse(cue.text) and dynamically pops up an interactive "Buy Now" widget over the video!
๐ป Interactive Code Playground
Starter Code
Line-by-Line Code Breakdown
- Line 66 (
kind="captions"):- Contains full sound effect annotations (
[UPBEAT MUSIC PLAYING]), meeting WCAG AA requirements for deaf and hard-of-hearing viewers.
- Contains full sound effect annotations (
- Line 78 (
kind="chapters"):- Provides synchronized time ranges mapping to descriptive section titles.
- Lines 102โ108 (
item.addEventListener('click', ...):- Enables instant jumping to specific chapter timestamps when clicked by the user.
Expected Browser Render Output
+------------------------------------------------------------------------+
| Synchronized Chapter Navigation System |
| +------------------------------------+ +----------------------------+ |
| | | | VIDEO CHAPTERS | |
| | [ VIDEO CANVAS ] | | [1. Course Intro (0:00)]* | |
| | [UPBEAT MUSIC PLAYING] | | 2. Core Concepts (0:02) | |
| | Instructor: Welcome to lecture. | | 3. Summary (0:04) | |
| | | +----------------------------+ |
| | [ > ] [===o==================] 0:01| |
| +------------------------------------+ |
+------------------------------------------------------------------------+๐๏ธ Hands-On Exercise
๐ฏ The Challenge: Build a Timed E-Commerce Product Overlay using kind="metadata"
Instructions:
- Create a
<video>element withcontrols,crossorigin="anonymous", and the flower MP4 video. - Embed a
<track kind="metadata">with a Data URI containing JSON metadata payloads for two time ranges:- 0.0s to 2.5s:
{"product": "Botanical Fertilizer 500ml", "price": "$14.99"} - 2.8s to 5.0s:
{"product": "Ceramic Plant Pot", "price": "$24.50"}
- 0.0s to 2.5s:
- Use JavaScript to listen for track cue changes (
track.oncuechange) on the metadata track (settrack.mode = 'hidden'). - When a cue triggers, parse the JSON payload and render an interactive pop-up badge on top of the video showing the product name and price with a "Buy Now" button.
๐ Starter Code Sandbox
โ ๏ธ Common Pitfalls
- Using
kind="subtitles"When Transcribing Sound Effects:kind="subtitles"indicates a pure spoken dialogue translation. If your track includes descriptions of sound effects (e.g.,[THUNDER ROARS]), it must be declared askind="captions"to meet WCAG AA standards. - Forgetting
track.mode = 'hidden'for Metadata: If you create akind="metadata"orkind="chapters"track without settingtrack.mode = 'hidden'or'showing'in JavaScript, some browser engines will skip fetching the file to save bandwidth, leavingtextTrack.cuesempty (null). - Multiple
defaultAttributes: Marking more than one<track>element with the booleandefaultattribute is invalid HTML and leads to undefined browser behavior.
๐ก Pro Tips
- Automated Live Transcripts for SEO: Search engine bots index
<track kind="captions">files directly. Serving comprehensive WebVTT closed captions provides rich textual indexing for your video content on Google Search. - Track Mode Lifecycle States: A
TextTrackin JavaScript has three distinct modes:'disabled': The track is inactive and cues are not fetched.'hidden': The track is parsed and firescuechangeevents in JavaScript, but the browser does NOT render captions on the video canvas.'showing': Cues are parsed AND rendered on screen by the browser.
๐ Key Takeaways
kind="subtitles"is for dialogue translation;kind="captions"is for deaf/hard-of-hearing accessibility (including sound effects and speaker IDs).- Providing synchronized captions for pre-recorded video is mandatory for WCAG 2.1 Level AA compliance.
kind="chapters"allows building interactive, clickable table-of-contents navigation menus.kind="metadata"allows streaming synchronized JSON data payloads directly to JavaScript applications.- Use
TextTrack.mode = 'hidden'to parse cues in JavaScript without native visual rendering. - --