agyanadda@gmail.com

HTML Audio

HTML Media 1 min read Updated Nov 30, 2026 Topic 20 of 33

The <audio> element plays sound files on your page.

Useful attributes

  • controls — shows play, pause and volume buttons (always add it).
  • autoplay — starts automatically (most browsers block this unless muted).
  • loop — repeats the audio.
  • muted — starts with no sound.

Add several <source> files so every browser finds a format it supports. MP3 works almost everywhere.

Example

Example — Audio player HTML
<audio controls>
  <source src="https://www.w3schools.com/html/horse.mp3" type="audio/mpeg">
  Your browser does not support audio.
</audio>

The text inside appears only in very old browsers that cannot play audio.

Try it Now »

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which attribute shows the play/pause buttons?

Exercise 2 True / False

Most browsers allow audio to autoplay with sound.

Frequently Asked Questions

MP3 is supported by all modern browsers and is the safest choice.