Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

HTML concept: media

HTML media elements manage resource selection, buffering, a timeline, playback, and timed tracks through asynchronous state machines.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

resource selection → network/ready state → playback timeline + tracks

The audio and video elements can use their own src or child source elements; the browser selects the first suitable candidate, and a type hint can avoid an unnecessary fetch. Container support does not guarantee support for every codec.

networkState describes resource handling, while readyState describes data available at the current position. preload is only a hint, and play() returns a promise that can reject because of autoplay policy, a missing source, or decoding failure.

A track child can provide subtitles, captions, descriptions, chapters, or metadata; srclang gives the data language. Captions should include important non-speech audio, and custom controls must retain keyboard operation and accessible names.

The example creates a track with addTextTrack(), adds a VTTCue, and observes initial NETWORK_EMPTY and HAVE_NOTHING states. The track and cue lists change without fetching or playing a file.

Examples

<!doctype html>
<meta charset="utf-8">
<video id="media"></video>
<output id="result"></output>
<script>
const media = document.querySelector("#media");
const track = media.addTextTrack("captions", "English", "en");
track.mode = "hidden";
track.addCue(new VTTCue(0, 2, "Hello"));
result.textContent = `network=${media.networkState}; ready=${media.readyState}; tracks=${media.textTracks.length}; cues=${track.cues.length}; mode=${track.mode}`;
</script>

Result

network=0; ready=0; tracks=1; cues=1; mode=hidden

The executed example verifies the track model and initial states; it does not prove codec support, synchronization of a real WebVTT file, or autoplay permission.

Sources