๐ŸŽฌ Chapter 32: Video in HTML

Subtitle Kinds, Chapters & Accessibility

`subtitles` vs `captions` (WCAG 2.1 AA), `descriptions`, `chapters` Navigation, and `metadata` Data Streams

LEARNING OBJECTIVES โŒต
  • Understand the legal, technical, and semantic differences between kind="subtitles" and kind="captions" under WCAG 2.1 AA accessibility standards.
  • Master all 5 distinct kind attribute values: subtitles, captions, descriptions, chapters, and metadata.
  • 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.
๐ŸŽฌ INTERACTIVE VISUAL PIPELINE Core Architecture Simulation
๐ŸŒ
1. Input
Directives & Tags
โš™๏ธ
2. Parse
Tokenizer & AST
๐ŸŒณ
3. Layout
Box Model & Flow
๐ŸŽจ
4. Render
GPU Paint & Composite
PHASE 1: INPUT & DIRECTIVES
Browser receives declarative markup stream, parsing tag tokens and initializing component state.

๐Ÿ“– The Mental Model & Story (Intuitive Foundation)

Imagine watching a tense mystery movie:

  1. 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.
  2. 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):

  1. Captions Must Be Synchronized: Text must appear at the exact moment audio is heard (within 100ms tolerance).
  2. Equivalent Content: All dialogue, non-speech audio cues (screams, doorbells, applause), and emotional tone in music must be transcribed.
  3. 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.
  • 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


SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
HTML STARSHIP CODE TERMINAL playground.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...
+------------------------------------------------------------------------+
| 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:

  1. Create a <video> element with controls, crossorigin="anonymous", and the flower MP4 video.
  2. 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"}
  3. Use JavaScript to listen for track cue changes (track.oncuechange) on the metadata track (set track.mode = 'hidden').
  4. 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

SYS: ACTIVE
HULL: 98%
CORE: STABLE
NET: ONLINE
STARTER CODE SANDBOX exercise.html
LIVE RENDER & DIAGNOSTICS CORE TEMP: 45ยฐC
INSPECTING DOM: VALID
TAGS: SCANNING...

โš ๏ธ Common Pitfalls

  1. 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 as kind="captions" to meet WCAG AA standards.
  2. Forgetting track.mode = 'hidden' for Metadata: If you create a kind="metadata" or kind="chapters" track without setting track.mode = 'hidden' or 'showing' in JavaScript, some browser engines will skip fetching the file to save bandwidth, leaving textTrack.cues empty (null).
  3. Multiple default Attributes: Marking more than one <track> element with the boolean default attribute is invalid HTML and leads to undefined browser behavior.

๐Ÿ’ก Pro Tips

  1. 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.
  2. Track Mode Lifecycle States: A TextTrack in JavaScript has three distinct modes:
    • 'disabled': The track is inactive and cues are not fetched.
    • 'hidden': The track is parsed and fires cuechange events 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.
  • --
โญ LEARN: HTML ๐ŸŒŸ โš”๏ธ QUIZ BATTLE ARENA // ACTIVE
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 1 / 3

What is the critical difference between kind="subtitles" and kind="captions"?

Question 1 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 2 / 3

Which track kind should be used when transmitting synchronized JSON coordinates or e-commerce payloads to JavaScript?

Question 2 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP
3x
STREAK!
BONUS ACTIVE
COMBO
? Question 3 / 3

What TextTrack.mode state must be assigned in JavaScript to receive cuechange events while suppressing native visual caption rendering?

Question 3 / 3 Topic: HTML Fundamentals
00:45 REMAINING
XP REWARD
+250 XP