How to Add Captions to HTML Video with WebVTT
Published · Updated
To add captions to an HTML video, write a WebVTT file, serve it alongside the video, and point a <track> element at its URL. Play the deployed video with captions on to check timing, wording, and readability.
Decide what the captions need to cover
Captions include spoken words and meaningful audio information, such as a door closing when it matters to the story. Subtitles often translate speech for someone who can hear the audio. Include sounds that carry information, not just dialogue. The W3C Web Accessibility Initiative guide to captions explains the content that captions should convey.
For a silent decorative loop, captions may add nothing. For a narrated product demo, tutorial, interview, or case study, write down the speech and the audio cues that carry information. If the video shows essential information that is never spoken, captions alone cannot describe it; consider narration or a separate text description.
Create a WebVTT file
WebVTT is a text format for timed cues. Save the file as UTF-8 with a .vtt extension. The first line is WEBVTT; a blank line separates it from the first cue. Each cue has a start time, an arrow, an end time, and text. This small example uses the timestamp form documented in the MDN WebVTT format guide:
WEBVTT
00:00:01.000 --> 00:00:03.500
Open the export panel.
00:00:03.500 --> 00:00:06.000
Choose a format for the website video.
00:00:06.000 --> 00:00:08.500
[Click] The export begins.
Name it something specific, such as product-demo.en.vtt. Keep each cue long enough to read without leaving it on screen after the relevant audio has ended. Break dense sentences at natural pauses. Review automatic transcripts for incorrect names and timing, then watch every cue with the exported video.
Keep the media and text in sync. If you trim the opening of the video after writing captions, update the cue times too. Check the exported delivery copy rather than only the editing master.
Connect the captions to the video
Put the video and VTT file on your site, then add a <track> inside the video element. Set kind="captions", a human-readable label, and the language code in srclang. The MDN track element reference describes these attributes and how the browser associates a text track with media.
<video
controls
playsinline
preload="metadata"
poster="/media/product-demo-poster.webp"
width="1280"
height="720"
>
<source src="/media/product-demo.webm" type="video/webm" />
<source src="/media/product-demo.mp4" type="video/mp4" />
<track
kind="captions"
src="/media/product-demo.en.vtt"
srclang="en"
label="English"
default
/>
<a href="/media/product-demo.mp4">Download the product demo</a>
</video>
The default attribute selects an initial track when the browser has no more suitable user preference; it does not replace the visitor’s caption controls. If you add several language tracks, give each one its own file, label, and srclang. Only one track should have default. Review translated tracks against the same exported video.
This example uses the same source fallback approach described in HTML video playback troubleshooting. If you need help choosing a preview image, see the HTML video poster guide. The VTT file is separate from both the poster and video files.
Check the deployed VTT response
Open the video page, turn captions on using the player controls, and confirm that the first cue appears at the intended time. Then inspect the VTT request in the browser’s Network panel. Its URL must point to the actual deployed text file. A missing path can return a website’s HTML fallback with a successful-looking status, leaving the player with no usable captions. Compare the response body with the VTT source, including the opening WEBVTT line.
Serve the file as text/vtt, the media type identified by the WebVTT specification. If the caption file is on another origin, check the cross-origin setup for the video and the text-track response. Keeping the file on the same site as the page is often simpler for a small self-hosted video.
A command-line response check can catch a missing path or wrong type before a browser review:
curl -i https://example.com/media/product-demo.en.vtt
Expect the VTT body, not an HTML page. Do this against the public URL, since a local development server and the production host may handle unknown paths differently.
Review captions with and without sound
- Play the entire exported video muted and read every cue. Check names, terminology, punctuation, and important sounds.
- Play it with sound and confirm each cue begins and ends near the matching audio.
- Use the keyboard to start playback and find the caption control. Test the browsers and devices your audience uses.
- Check captions over both bright and dark scenes. If the player’s styling makes them hard to read, test a different player or presentation.
- Repeat the check after changing the video edit, caption file, hosting path, or player.
The W3C guide also recommends a transcript for people who need or prefer the information as continuous text. A transcript can be searched and skimmed without playing the video; it does not replace synchronized captions.
Keep the VTT source with the video master. After changing the edit, update the cue times and test both files on the public page. The landing-page video guide covers the surrounding player and loading decisions.