Video: add controls, a poster, captions and a written alternative
Build a video example that students can start themselves. Explain the visible player and its separate files, then add timed captions without confusing them with a full written description.
Video combines a moving picture with optional sound. HTML's video element embeds the player; it does not record or edit the clip. The ZIP includes media/moving-dot.mp4, an original six-second demonstration. A green dot moves from left to right, and two quiet tones sound during the clip. There is no speech.
The supplied images/moving-dot-poster.png is a still image of the starting view. A poster is a picture the player can show before video playback. It does not replace the video resource or create its frames.
Read the player syntax
HTML fragment — part of a document
<videocontrolswidth="320"height="180"poster="images/moving-dot-poster.png"preload="metadata"><sourcesrc="media/moving-dot.mp4"type="video/mp4">
Your browser does not support this video player.
</video>
Controls supplies native play and pause controls, with other actions depending on the device. Width and height are integer CSS-pixel dimensions without px units. Source identifies a real video file, and type is a format hint. Do not use a normal watch-page URL as though it were a direct MP4 file. Services with hosted players usually provide their own embedding rules.
Complete program: video-practice.html
video-practice.html
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>A Short Motion Practice Clip</title></head><body><h1>Watch the moving dot</h1><p>Start the six-second clip when you are ready.</p><videocontrolswidth="320"height="180"poster="images/moving-dot-poster.png"preload="metadata"><sourcesrc="media/moving-dot.mp4"type="video/mp4">
Your browser does not support this video player.
</video><p>Written equivalent: a green dot moves steadily from left to right on a pale background. Quiet tones sound near the start and around three seconds. There is no speech.</p><p><ahref="media/moving-dot.mp4">Open the practice video directly</a></p></body></html>
Browser previewDocument title: A Short Motion Practice Clip
This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Expected result: a player shows the starting image and waits for your action. Press Play and compare the movement with the written description. Pause around the middle. A download may be needed before seeking can work. Player appearance and fullscreen availability can vary.
Formats, codecs and alternative sources
MP4 and WebM are common media containers: file structures that hold video and possibly audio data. A codec describes how the data within them is encoded. A .mp4 extension alone does not guarantee that every browser supports the enclosed codecs.
Source children can offer genuine alternatives in order, such as an MP4 and a WebM version of the same clip. Use type="video/mp4" or type="video/webm" as appropriate. Do not list files you have not created or change an extension to pretend the encoding changed. The supplied MP4 uses H.264 video and AAC audio; test the environments you support.
Playback settings and autoplay limits
Setting
Purpose
controls
Give the reader native playback controls
poster
Supply a still image before playback
preload
Hint how much media to load ahead of playback
muted
Start with sound muted
loop
Repeat after reaching the end
autoplay
Request automatic playback
playsinline
Request playback within the page where supported
Muted, loop, autoplay, playsinline and controls are boolean. Remove the attribute to turn it off. Muted="false" still requests the default muted state. Autoplay with sound is commonly blocked; even muted autoplay is not an unconditional guarantee. Prefer reader-controlled playback for lessons.
Preload="metadata" is a hint about fetching information such as duration. It is not a guarantee of an exact byte count. Playsinline is especially useful on devices that might otherwise use another playback presentation, but device behaviour still matters.
Keep the video resources together
1Source: the actual moving picture and sound
2Poster: the starting still image
3Track: the timed text file
4Visible description: important sound and motion
Test separate caption tracks on an HTTP server. They are not automatically generated.
Captions and subtitles
Captions provide timed text for speech and meaningful non-speech sounds. Subtitles commonly provide dialogue text, often translated. Neither automatically supplies a full explanation of essential visual actions for someone who cannot see the video.
Use a track element inside video to identify a timed text file. A track is void and has no closing tag. Put it after the source elements. The file format is normally WebVTT, a text format with time ranges and cue text.
These cues describe the actual non-speech sounds in our example. The visible page description explains the dot's motion. For a real spoken lesson, captions must include the actual spoken words and meaningful sounds with correct timing; a few sample cues are not enough.
Complete program: captioned-video.html
captioned-video.html
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>Motion Clip with Sound Captions</title></head><body><h1>Play a clip with optional captions</h1><videocontrolsplaysinlinewidth="320"height="180"poster="images/moving-dot-poster.png"preload="metadata"><sourcesrc="media/moving-dot.mp4"type="video/mp4"><trackkind="captions"src="media/moving-dot-en.vtt"srclang="en"label="English sound captions"default>
Your browser does not support this video player.
</video><p>Written equivalent: the green dot moves left to right for six seconds. A soft tone sounds near the start and another around three seconds. There is no speech.</p><p><ahref="media/moving-dot-en.vtt">Read the caption file</a></p></body></html>
Browser previewDocument title: Motion Clip with Sound Captions
This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here. Separate caption tracks are not loaded in this preview. Use the saved example files on a local HTTP server to test captions, as explained in the chapter.
Expected result: a player with a caption track that can be selected through its controls. Srclang names the track language, label is the readable choice name, and default requests initial selection subject to browser preferences. Only one track in a media element should be marked default.
The lesson preview plays the supplied clip but does not load the separate caption track. To test captions, extract the ZIP and serve the folder through a local HTTP server, rather than relying on file://. For example, with Python installed, open a terminal in the extracted folder, run python -m http.server 8000 --bind 127.0.0.1, and visit http://127.0.0.1:8000/captioned-video.html. Stop that temporary server with Ctrl+C. The media and VTT should share the document's origin, and a web server should send VTT as text/vtt.
What a written alternative should cover
A useful video transcript or description includes the meaningful spoken content and important visual information. If a teacher silently points at a code error, text that reports only the teacher's words may miss the lesson. Audio description can supply important visuals through an additional spoken explanation. Choose alternatives according to what the actual clip communicates.
Do not add alt to video expecting it to work like img. Keep the equivalent in visible page content or provide a clearly labelled reachable alternative. Captions, transcripts and usable controls solve related but different needs.
Problem and solution: the video plays but captions do not
Problem: the MP4 works when double-clicked, but the VTT fails in a locally opened HTML file.
Solution: test the full example through a local HTTP server. Check the VTT path, WEBVTT header, blank lines, time ranges, language and server content type. Local-file security rules can differ from normal same-origin HTTP serving. Do not assume that a working video proves its text track loaded.
Common mistakes and useful tips
Confusing a poster with a video resource.
Using a video-sharing watch page as a direct source file.
Writing width="320px" in a numeric HTML width attribute.
Expecting autoplay to work identically everywhere.
Supplying empty or unrelated caption text.
Putting fallback text inside video and assuming every resource error reveals it.
Offering captions without a way to understand important visual information.
Practice questions
What does poster supply?
What do controls and playsinline request?
Do captions and a full visual description have identical jobs?
Which element connects a VTT file to video?
Why might a caption track need testing over HTTP rather than file://?
Run the supplied clip, pause midway and compare it with the written equivalent. Serve the extracted examples locally and check both caption cues against the two tones.
Check your practice answers
A still image for the player before playback, not the video frames themselves.
No. Captions convey timed speech and meaningful sounds. Important visual actions may need description as well.
Track, with src pointing to the VTT file and suitable language and kind attributes.
File-origin restrictions and track fetching rules differ. Same-origin HTTP serving with text/vtt is a more reliable test.
Keep every media file at its supplied path. Check the dot's movement, both sound cues and the caption control in your browser. Stop the temporary local server afterwards.
Interview questions
Is poster an accessible replacement for video content?
No. It is a starting image. It does not communicate the full meaningful sound and motion. Provide appropriate captions, transcripts and descriptions for the actual content.
What does track add to a video?
It identifies a timed text resource, with a kind such as captions or subtitles and language information. The browser can use it during playback; it does not generate captions from speech automatically.
Why test a codec as well as a file extension?
A container can hold differently encoded streams. The browser must support the streams actually present, not merely recognise the extension.
Does hiding a download control protect the video?
No. Removing a control is not access control or copy protection. A protected service must check access before delivering resources.
Quick revision
Video needs real media, usable controls and appropriate dimensions.
Poster, source and track refer to separate resources.
Autoplay is a request; readers should control lesson playback.
Test captions over HTTP and keep a useful written equivalent available.