liveBook · Manning

Audio element

As explained in Web Design Playground, Second Edition

The HTML audio element embeds audio content in a web page and can provide controls for playback.

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

How Web Design Playground, Second Edition covers it

How deep it goes
Explains direct embedding, playback attributes, and multiple sources, while only briefly framing containers, codecs, and format complexity.
Examples
Uses single-file and multiple-source players with MP3, WAV, WebM, Ogg, and MP4 audio examples.
What it assumes
Assumes basic HTML element and attribute syntax while defining audio-specific attributes and media-format terminology.
What you can do after
Build it from scratch by embedding one audio file or offering several formats with playback attributes.
How it connects
Connects the audio element with the video element, source element, media formats, containers, and codecs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.