CHAPTER 23 · HTML
Audio: add a player and keep the information available in words
Add a sound file with the browser's own controls. Understand sources, playback settings and fallback text, then provide a written alternative so the lesson does not depend on hearing the sound.
Download example files (ZIP)The player and recording are different things
Read the basic syntax
<audio controls src="media/practice-tones.wav">
Your browser does not support this audio player.
</audio>Complete program: audio-practice.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hear Two Practice Tones</title>
</head>
<body>
<h1>Try the audio controls</h1>
<p>Play a six-second example with two quiet tones. Nothing plays until you choose Play.</p>
<audio controls preload="metadata" src="media/practice-tones.wav">
Your browser does not support this audio player.
</audio>
<p>Written equivalent: a short tone sounds near the start, followed by another around three seconds. There is no speech.</p>
<p><a href="media/practice-tones.wav">Open the tone recording directly</a></p>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Source choices and type labels
Complete program: audio-source.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Audio Source and Written Alternative</title>
</head>
<body>
<h1>Read the sound as well as playing it</h1>
<audio controls preload="none">
<source src="media/practice-tones.wav" type="audio/wav">
Your browser does not support this audio player.
</audio>
<h2>Written equivalent</h2>
<p>Two short quiet tones sound during six seconds, near the start and around the middle. There are no spoken instructions.</p>
<p><a href="media/practice-tones.wav" download>Download the practice sound (WAV)</a></p>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
- 1Audio: the playback element
- 2Controls: native buttons
- 3Src or source: the recording address
- 4Visible text: the written equivalent
Fallback-only text is not a reliable error message for a failed resource.
Common playback settings
A transcript is more than a backup button
Problem and solution: controls appear but there is no sound
Common mistakes and useful tips
Uploading the HTML but forgetting the audio file. Using audio/mp3 instead of the normal MP3 type audio/mpeg. Adding source alternatives that do not exist. Setting both audio src and a competing source list without understanding precedence. Hiding the only written alternative inside fallback content. Assuming preload="none" forbids all future downloads. Starting sound automatically or leaving students with no clear playback control.
Practice questions
What does controls request? Why does a visible player not prove that the file loaded? What is the difference between audio src and source children? Does autoplay="false" turn autoplay off? Where should a useful transcript be available? Save the audio example and its media folder. Test play, pause, volume and the written alternative. Temporarily change the filename and explain how the failure differs from an unsupported audio element.
Check your practice answers
The browser's native playback interface. The element can render even when its resource is missing, unsupported or unavailable. Src supplies a direct resource. Source children offer candidate resources when the audio element has no own src. No. Autoplay is boolean; remove the attribute. In visible, reachable page content or a clear transcript link, not only inside unsupported-element fallback. Keep the supplied WAV at its matching path. A broken resource in a supporting browser may leave a failed player without revealing the fallback sentence. Restore the filename afterwards.
Interview questions
Is JavaScript required for a basic audio player?
Is preload a command that browsers must follow exactly?
Why put a file link outside audio?
What should an accessible audio lesson include?
Quick revision
Audio supplies a player; the resource supplies the sound. Use controls, real source files and correct type labels. Boolean settings depend on presence, and preload is a hint. Keep transcripts and useful links outside fallback-only content.