Audio, video, source, and captions
Native media elements provide browser playback controls, while source and track elements help offer compatible files and accessible text.
✓ What you will learn in this topic
- Explain the purpose of Audio, video, source, and captions in a real HTML document.
- Choose and apply the elements shown in both examples.
- Recognize the specific mistake described in this lesson.
Concept explanation
Audio and video can use controls so visitors can start, pause, and adjust playback. Source elements let the browser choose among supported formats. A track with kind=\"captions\" can provide synchronized dialogue and meaningful sounds; a transcript is also valuable. Include fallback text for browsers that cannot play the media. Avoid autoplaying sound because it interrupts visitors and can be difficult to stop.
Syntax
Place one or more source elements inside audio or video, enable controls, and add a captions track to video.
Example 1: a small page
Controls expose playback and the fallback sentence is shown if the browser lacks support.
<audio controls>
<source src=\"birds.mp3\" type=\"audio/mpeg\">
Your browser cannot play this audio.
</audio>Expected result: A native audio player appears when the browser supports the provided file.
Example 2: a practical page
The video has controls, a poster image, a source, and a selectable English captions track.
<video controls width=\"720\" poster=\"garden-cover.jpg\">
<source src=\"garden.mp4\" type=\"video/mp4\">
<track kind=\"captions\" src=\"garden-en.vtt\" srclang=\"en\" label=\"English\" default>
Your browser cannot play this video.
</video>Expected result: A video player displays the garden cover and offers playback controls and English captions.
Common mistakes
Do not omit alt on img; use meaningful text for informative images and an empty value for decorative images.
Best practices
Provide intrinsic image dimensions, captions where they add context, and captions or transcripts for media people cannot hear or see.
Practice exercise
Build an event page with an informative photo, a decorative icon, an audio clip with a transcript link, and a video with captions.
Lesson summary
- Use native media controls, compatible source files, and synchronized captions or transcripts.
- Provide intrinsic image dimensions, captions where they add context, and captions or transcripts for media people cannot hear or see.
Knowledge check
Which element can provide synchronized captions for video?
Show the explanation
A track element with kind=\"captions\" links a WebVTT captions file to the video.
Practical example
html<audio controls>
<source src=\"birds.mp3\" type=\"audio/mpeg\">
Your browser cannot play this audio.
</audio>
Expected result:
A native audio player appears when the browser supports the provided file.
Hands-on practice task
Build an event page with an informative photo, a decorative icon, an audio clip with a transcript link, and a video with captions.
In this section
Other lessons in Images and Media
Broaden your knowledge