HTML Tutorial

HTML Tag: <audio>

Usage

The <audio> tag embeds audio content into HTML documents for playback.

Attributes

  • src: URL of the audio file
  • controls: Enable or disable playback controls (e.g., play/pause)
  • autoplay: Start playback automatically
  • loop: Repeat the audio indefinitely
  • muted: Start playback without sound

Examples

  • Basic audio playback:
<audio src="song.mp3" controls></audio>
  • Enable autoplay and loop:
<audio src="background-music.mp3" autoplay loop></audio>
  • Mute audio:
<audio src="sound-effect.mp3" muted></audio>

Example: Exploring the <audio> Tag

<!DOCTYPE html>
<html>
<body>

<audio controls>
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

</body>
</html>

Accessibility

  • Provide alternative text for screen readers using the aria-label attribute.
  • Use captions or transcripts for accessibility to those with hearing impairments.