This tutorial aims to guide you on how to make your video content more accessible by adding captions and transcripts using HTML. Captions and transcripts make your videos more accessible to a broader audience, especially those who are hard of hearing.
By the end of this tutorial, you will learn:
- How to add captions to videos using HTML
- How to add transcripts to videos using HTML
Prerequisites:
- Basic understanding of HTML (HyperText Markup Language)
HTML provides the <track>
element which is used to specify text tracks for media elements (<audio>
and <video>
). The text tracks are specified as subtitles, captions, descriptions, chapters, or metadata. The source for the track file is given with the src
attribute, and the kind of text track is specified with the kind
attribute.
Captions are similar to dialogue-only subtitles, in addition to which they also include relevant parts of the soundtrack — representing background noises, phone rings, or other significant sounds.
To add captions to a video:
Convert your captions into a WebVTT (.vtt) file. WebVTT stands for "Web Video Text Tracks". It is a format for captions, subtitles, and screen descriptions, chapters, and metadata.
Add a <track>
element inside your <video>
element with the kind
attribute set to "captions", src
attribute pointing to your .vtt file, and label
attribute for user-readable title.
Transcripts are a text version of the speech and non-speech audio information needed to understand the content. They may include the same language as the original audio or a translation to another language.
To add transcripts to a video, you can place the text of the transcript below the video, inside a <div>
or <p>
tag. You could also make the transcript interactive by synchronizing it with the video.
<video controls>
<source src="myVideo.mp4" type="video/mp4">
<track kind="captions" src="captions_en.vtt" srclang="en" label="English">
</video>
Explanation:
<video>
tag is used to embed video content.<source>
tag is used to specify multiple media resources for media elements, such as <video>
, <audio>
, <picture>
, and <iframe>
.<track>
tag is used to specify external text track resources, such as captions, subtitles, etc.<video id="myVideo" controls>
<source src="myVideo.mp4" type="video/mp4">
</video>
<div id="transcript">
<p>Transcript: Hello, welcome to our tutorial...</p>
</div>
Explanation:
<div>
tag defines a division or a section in an HTML document.<p>
tag defines a paragraph.We have learned how to use HTML to add captions and transcripts to videos, making them accessible to a wider audience. You can now try adding captions and transcripts to a video of your choice.
<!-- Your code here -->
<!-- Your code here -->
Solutions:
<video controls>
<source src="myVideo.mp4" type="video/mp4">
<track kind="captions" src="captions_en.vtt" srclang="en" label="English">
<track kind="captions" src="captions_es.vtt" srclang="es" label="Spanish">
</video>
<video id="myVideo" controls>
<source src="myVideo.mp4" type="video/mp4">
</video>
<div id="transcript" style="font-size:16px; color:blue;">
<p>Transcript: Hello, welcome to our tutorial...</p>
</div>
To further practice, try adding more languages to the captions and changing the style of the transcript. You can also try to make the transcript interactive by synchronizing it with the video.