Add a video with captions.
What to build
A video with a fallback format and English captions.
Requirements
- A
videowithcontrols,width="640",height="360"andposter="cover.jpg". - A first
source:class.webmwithtype="video/webm". - A second
source:class.mp4withtype="video/mp4". - A
trackwithkind="captions",src="class.en.vtt",srclang="en"andlabel="English".
Constraints
The autoplay attribute must not be used.
Example
The syntax part of the lesson shows the same shape.
Why it works
The browser tries the sources in order, and the captions appear in the player's menu for anyone who needs them.
Hints
Hint 1
track goes inside video, after the source elements.
Hint 2
Width and height reserve the space before the video loads.
Solution
Show one correct solution (try it yourself first)
<video controls width="640" height="360" poster="cover.jpg"> <source src="class.webm" type="video/webm"> <source src="class.mp4" type="video/mp4"> <track kind="captions" src="class.en.vtt" srclang="en" label="English"> </video>