Links & Media Lesson 19 of 42
HTML Audio and Video
Add sound and video to a web page with the audio and video elements. Learn controls, autoplay rules, poster images, file formats and captions.
Before HTML5, playing a video on a website needed extra plugins like Flash. Today, the browser can play audio and video on its own, using two simple elements: <audio> and <video>. In this lesson you'll learn how to add them, which options to use, and how to keep them friendly for your visitors.
The video element
<video src="videos/school-tour.mp4" controls width="640" height="360"></video>
src— the video file.controls— shows the play button, volume, timeline and fullscreen button. Without it, the reader has no way to start the video!widthandheight— the size of the player.
<video controls width="400" height="225" poster="/img/jeepney.svg">
<source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4" type="video/mp4">
Sorry, your browser can't play this video.
</video>
This example uses a short free video of a flower. Press play to try it.
Using source for different formats
Instead of src on the video itself, you can list one or more <source> elements inside it. The browser plays the first one it supports. The text inside <video> is shown only on very old browsers that can't play video at all.
<video controls width="640" height="360">
<source src="videos/tour.webm" type="video/webm">
<source src="videos/tour.mp4" type="video/mp4">
Your browser does not support video.
</video>
Today, MP4 (with H.264 video) plays almost everywhere, so one MP4 source is usually enough.
Useful video attributes
| Attribute | What it does |
|---|---|
controls | Shows the player controls |
poster="image.jpg" | The picture shown before the video starts |
autoplay | Starts playing on its own (only works if also muted) |
muted | Starts with the sound off |
loop | Plays again from the start when it ends |
playsinline | On iPhone, plays inside the page instead of going fullscreen |
preload="none" | Doesn't download anything until the user presses play — saves data |
About autoplay
Videos that suddenly play loud sound are annoying — imagine opening a page in a quiet classroom or library! Because of this, browsers block autoplay with sound. Autoplay only works if the video is also muted:
<video src="videos/background.mp4" autoplay muted loop playsinline></video>
The audio element
<audio> works the same way, minus the picture. It's perfect for podcasts, music samples, pronunciation guides, or a recorded announcement.
<audio controls>
<source src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3" type="audio/mpeg">
Your browser does not support audio.
</audio>
Common audio formats: MP3 works everywhere; M4A/AAC and OGG are also common.
A practical example: a pronunciation guide
Teachers and language learners can use audio for vocabulary:
<h3>Learn Cebuano Greetings</h3>
<p><strong>Maayong buntag</strong> — Good morning</p>
<audio controls preload="none" src="audio/maayong-buntag.mp3"></audio>
<p><strong>Salamat kaayo</strong> — Thank you very much</p>
<audio controls preload="none" src="audio/salamat-kaayo.mp3"></audio>
Captions and subtitles
Captions help deaf and hard-of-hearing viewers, people watching without sound on the jeep, and people still learning the language. Add them with the <track> element and a .vtt subtitle file:
<video controls width="640" height="360">
<source src="videos/lesson.mp4" type="video/mp4">
<track src="captions/lesson-en.vtt" kind="subtitles" srclang="en" label="English">
<track src="captions/lesson-fil.vtt" kind="subtitles" srclang="fil" label="Filipino">
</video>
A .vtt file is a simple text file with times and lines of dialogue:
WEBVTT
00:00:01.000 --> 00:00:04.000
Magandang umaga, mga estudyante!
00:00:04.500 --> 00:00:08.000
Today we will learn about HTML video.
Should you host video yourself?
Video files are big. Hosting them yourself uses a lot of storage and bandwidth. For long videos, most websites upload to YouTube or another video service and embed the player instead. You'll learn how in the next lesson, on iframes. Use <video> for short clips you own, like a 10-second demo or a background animation.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04