The HTML <audio> element embeds sound in a web page. Think of it as a tiny player waiting for a soundtrack; add controls when visitors should manage playback themselves. section 6.16 section 6.17
Build the element one attribute at a time:
- src points to a single audio file. section 6.16
- controls displays playback controls in the audio window. section 6.16
- autoplay starts playback after enough audio has downloaded for smooth playback. section 6.16
- loop restarts playback from the beginning whenever the audio ends. section 6.16
- Use source elements instead of audio's src when offering multiple formats; each source supplies a file location and type. section 6.16
One player, several formats
A single-format player can point directly to an MP3. For broader format coverage, list alternatives inside the audio element, such as MP3, WAV, WebM, Ogg, and MP4 audio files. section 6.16 section 6.14
<audio controls
autoplay
loop>
<source src=”/audio/music.mp3”
type=”audio/mp3”>
<source src=”/audio/music.wav”
type=”audio/wav”>
<source src=”/audio/music.webm”
type=”audio/webm”>
<source src=”/audio/music.ogg”
type=”audio/ogg”>
<source src=”/audio/music.m4a”
type=”audio/mp4”>
</audio>
Compare the complete multiple-format pattern, including playback attributes, source locations, and declared audio types. section 6.16
