HTML Audio: Playback Controls and Loading
Play an audio file
The audio element embeds sound. Set src to a resource URL and add controls for the browser’s play, pause and volume interface. The sample is a one-second generated tone. These examples use the original files in media-fixtures/; open the supplied preview from a local static server or place the files at the shown paths.
<audio src="media-fixtures/tone.wav" controls></audio>The player should appear; choose Play to hear the tone.
Boolean attributes and looping
controls, loop, muted and autoplay are Boolean attributes: presence means enabled, even with the text value false. Remove an attribute to disable it. A muted track can be unmuted by the user; avoid starting sound without consent.
<audio src="media-fixtures/tone.wav" controls loop muted></audio>Playback begins only on request; it repeats and starts muted.
Choose a loading hint
preload="none" requests minimal preloading; metadata requests information such as duration; auto permits more data to be loaded. These are hints, not download guarantees. Autoplay, if allowed, can override preload.
<audio src="media-fixtures/tone.wav" controls preload="none"></audio>The browser may defer loading until Play is pressed.
Common mistakes and practice
Do not write autoplay="false"; omit it. Try changing preload and loop. Provide a text transcript for meaningful spoken or non-speech audio; the sample contains only a steady tone.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Audio: Playback Controls and Loading — Knowledge Check
Apply the media or embedding concepts from this lesson.
How do you disable autoplay in markup?
What does preload="metadata" promise?
Which feature enables browser playback UI?
A short track should repeat when playback ends. Which attribute expresses that?
Why should an audio sample not depend on autoplay for essential information?