Once images have made your page lively to look at, it’s time for motion and sound. A video player or audio player with a play button can also be placed with a single HTML tag. What we use is <video> and <audio>. They’re named exactly for what they do, so they’re easy to remember.
Placing a video
You show a video with <video>. The important part is controls. Adding it makes a control panel appear, with play, pause, volume, and so on.
<video src="/movie.mp4" controls></video>| What you write | Meaning |
|---|---|
<video> | The video player part |
src="..." | Which video file to show (its location) |
controls | The mark that shows the control panel, like the play button |
If you forget to write controls, the video is placed but no play button appears, leaving it in a “can’t-do-anything” state. To start with, just remember to write the two as a set.
<video controls> in action. You can see the control panel — the play button and the rest — lined up below the screen.Placing a sound
Sound is <audio>. It’s used just like <video>.
<audio src="/sound.mp3" controls></audio>This shows an audio player with a play button. Use it when you want to place BGM, a sound effect, narration, and so on. Here’s what it actually looks like.
<audio controls> in action. When you press play, a short “pop” sound plays. <video> gives you this same kind of player with a control panel, only for video.Two words you’ll often add
Besides controls, there are two more worth keeping in mind.
<video src="/movie.mp4" controls autoplay muted></video>| What you write | Meaning |
|---|---|
autoplay | Plays automatically when the page opens |
muted | Starts in a sound-off state |
loop | Plays over again once it reaches the end |
muted). The point is that it plays without you clicking.Summary of this lesson
- Video is
<video>, sound is<audio> - Adding
controlsmakes it a player with a play button - If you autoplay (
autoplay), includemuted(sound off) too