Lesson 45 of 51 · Module 7, lesson 5 of 11 · 3 min
Audio
Add sound with a player, a fallback format and a transcript.
What you'll learn
- How to add sound with
<audio>- How to offer a second format as a fallback
- Why every audio clip needs a transcript
Why this matters
A recorded tip, a podcast, the pronunciation of a word: audio is useful. But a deaf visitor, or someone in a quiet library, gets nothing from it — unless you also give the words as text.
An audio player
Save soup-tip.mp3 into your media folder (right-click → Save link as…).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cooking tip</title>
</head>
<body>
<h1>Today's cooking tip</h1>
<audio controls>
<source src="media/soup-tip.mp3" type="audio/mpeg">
<source src="media/soup-tip.ogg" type="audio/ogg">
<p>Your browser cannot play audio. <a href="media/soup-tip.mp3">Download the tip</a>.</p>
</audio>
<h2>Transcript</h2>
<p>Here is a cooking tip. Add a little salt at the end, then taste the soup before you serve it.</p>
</body>
</html>
What you'll see: a small player bar with a play button and a time line, and the transcript under it.
controlsshows the player. Without it, the audio is invisible.- Two
<source>elements: the browser plays the first format it supports. MP3 plays in every current browser; the OGG file is an optional extra. type="audio/mpeg"is the type for MP3 files.
Always add a transcript
A transcript is the text of everything that is said. Put it right under the player, as in the example. It is the audio version of alt text. It also lets people find a sentence quickly, copy it, or translate it.
No autoplay
autoplay on audio is blocked by most browsers unless the audio is muted — and sound that starts by itself is a real problem for screen reader users, whose screen reader is suddenly drowned out. Let people press play.
Try it yourself
- Select the example and choose Try it, and play the tip.
- Remove
controls. The player disappears from the preview. Put it back. - Record a 10-second tip of your own on your phone, save it as MP3 in
media, and add it with a transcript.
Common mistakes
- No
controls. Nothing appears on the page. Fix: addcontrols. - No transcript. Deaf and hard-of-hearing visitors miss everything. Fix: add the text under the player.
- Wrong
type, such asaudio/mp3. Some browsers skip the source. Fix:audio/mpegfor MP3.
Check yourself
- What does the second
<source>do? - What is the audio version of
alttext? - What is the correct
typefor an MP3 file?
Answers
- It is a fallback: the browser plays the first format it supports.
- A transcript.
audio/mpeg.
Next: sometimes you want to show a whole page from somewhere else inside yours — a map, or a YouTube video. That is an iframe.

