An interview or sound sample can sit next to the text that gives it context. The HTML <audio> element embeds the recording so visitors can listen without leaving the page.

With controls present, the browser supplies Play, Pause, and volume controls. Leaving out autoplay lets visitors decide when the sound starts.

The recording stays in a separate file. A filename in src points to the same folder as the HTML page, so the file must be available alongside the page wherever it is served.

Steps to embed audio in HTML:

  1. Create audio.html in a new empty test folder using your text editor.
  2. Copy a playable MP3 into the same folder as audio.html under a simple name such as sample.mp3, using only ASCII letters, digits, and hyphens before the .mp3 extension.
  3. Enter the following markup in audio.html with your MP3 filename in src.
    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>Audio sample</title>
    </head>
    <body>
      <h1>Audio sample</h1>
      <audio controls src="sample.mp3"></audio>
    </body>
    </html>

    sample.mp3 stands for your audio file. The filename in src must match the filename on disk, including capitalization.

  4. Save audio.html.
  5. Open the saved audio.html in desktop Chrome.
  6. Click Play below the Audio sample heading.

    The player shows the Pause button and the elapsed time starts counting up. If playback never starts, check that the MP3 next to audio.html plays on its own and that its simple filename matches src, including capitalization.

  7. Click Pause while the elapsed time is advancing.
  8. Verify that the elapsed time stays at the paused position for several seconds.

    The Play triangle returns, and the elapsed time holds below the total duration. For the recording shown, it holds at 0:18 of 3:00.

Share this guide