MyInternships.in

HTML Tags

HTML5 <audio> Tag

The <audio> tag embeds sound content, such as music or podcasts, that visitors can play directly in the browser. It is a native HTML5 media element that needs no plugins.


The <audio> Tag

The <audio> element plays audio files natively in the browser. You can point it at a file with the src attribute or provide multiple <source> children so the browser can pick a format it supports. Add the controls attribute to show the built-in play, pause, and volume interface.

Content placed between the opening and closing tags acts as fallback text for browsers that cannot play audio.

Syntax

A player with built-in controls.
Example
<audio controls src="sound.mp3"></audio>

Example

An audio player with controls and a fallback message.
Example
<!DOCTYPE html>
<html>
  <body>
    <h1>Audio Player</h1>
    <audio controls>
      <source src="https://www.w3schools.com/html/horse.mp3" type="audio/mpeg" />
      Your browser does not support the audio element.
    </audio>
    <p>Press play to hear the sound.</p>
  </body>
</html>

More Examples

Using the loop and muted attributes.
Example
<!DOCTYPE html>
<html>
  <body>
    <p>This audio loops and is muted by default:</p>
    <audio controls loop muted>
      <source src="https://www.w3schools.com/html/horse.mp3" type="audio/mpeg" />
    </audio>
  </body>
</html>

Attributes

AttributeDescription
controlsShows the browser's built-in playback controls.
srcURL of the audio file (or use <source> children).
autoplayStarts playing automatically when the page loads.
loopRestarts the audio when it reaches the end.
mutedStarts the audio muted.
preloadHints how much to preload: none, metadata, or auto.
⚠️

Most browsers block autoplay with sound. To autoplay, you usually also need the muted attribute. Always include controls or a custom UI so users stay in control.

Key Takeaways

  • <audio> plays sound natively without plugins.
  • Add controls to show the built-in player.
  • Use <source> children to offer multiple formats.
  • autoplay with sound is usually blocked; combine with muted.
  • loop, muted, and preload fine-tune playback.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships