A clip can show motion or sound that is hard to describe in text. HTML lets you embed a video alongside the rest of the page, with browser controls for playback and a separate track viewers can turn on for captions.
WebVTT captions can include speech and sounds such as an alarm or a knock at the door. Each cue has a start and end time, so its text appears over the video when the sound occurs.
For a local preview, the HTML, video and captions can share a folder on a running test web server. Keeping them together lets the HTML refer to each file by name. The server should serve the WebVTT file as text/vtt.
Steps to embed a video in HTML:
- Save a copy of your H.264 MP4 as
demo.mp4in a freshvideo-demofolder on your local test site.The preview uses an MP4 with H.264 video and AAC audio.
- Create a caption file in your text editor with cue times and text that match your video.
WEBVTT 00:00:03.000 --> 00:00:34.000 [Low tone plays] 00:00:36.000 --> 00:01:09.000 [High tone plays]
The sample describes two tones. Each timing line gives the start and end in hours, minutes, seconds and milliseconds. A blank line goes after
WEBVTTand between cues. - Save the caption file as UTF-8 plain text named
captions.vttinvideo-demo. - Insert the video element immediately after the
Video demoheading in the markup.<video controls src="demo.mp4" width="640"> </video>
srcpoints to the MP4 in the same folder. Thecontrolsattribute shows the browser's player controls. - Insert the caption track immediately before </video>.
<track kind="captions" src="captions.vtt" srclang="en" label="English">kind=“captions”identifies the track as captions,srclang=“en”declares the language, andlabel=“English”names the option shown in the player. For another language, the code and label should both match the caption text. The HTML Standard defines the caption track attributes. - Save
video.html. - Open
video-demo/video.htmlfrom your local test site in desktop Chrome.If your server is at
http://localhost:8000, the address ishttp://localhost:8000/video-demo/video.html.
- Open the three-dot menu at the right end of the video controls.

- Open Captions in the video menu.

- Select your track's label in the captions menu.
The sample track is labeled English.
- Click Play at the left end of the video controls.

- Verify that the elapsed time advances from
0:00.
- Verify that the video displays your caption during its cue interval.
With the sample file,
[Low tone plays]appears over the video from 0:03 until 0:34. If the text is missing during the cue, check thatcaptions.vttis served from the same folder asvideo.htmland that its first line isWEBVTT.