Audio Tag in HTML
Syntax, Attributes, Formats, and Examples

HTML <audio> Tag: Let Your Page Speak

Want your webpage to play a melody, voice clip, or sound effect? The <audio> tag makes it easy. With a few lines of code, you can embed sound in your page — no plugins needed, no extra fuss.

Basic Syntax

<audio controls>
  <source src="banana-sound.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
[ Audio player appears here with play/pause ]

The <audio> element works much like <video>. It holds one or more <source> elements and may contain fallback text for unsupported browsers.

Common Audio Attributes

AttributeDescription
controlsDisplays play/pause interface
autoplayStarts playing as soon as it's ready
loopReplays audio after it ends
mutedStarts playback in muted mode
preloadInforms browser how to load the audio (none, metadata, auto)

Example: Autoplay and Loop

<audio autoplay loop muted>
  <source src="cherry-loop.mp3" type="audio/mpeg">
  Your browser does not support the audio tag.
</audio>

This setup loops the sound and plays it as soon as the page loads — silently if muted is set.

Supported Formats

Different browsers support different audio formats. Here are the most common:

  • MP3 — widely supported (audio/mpeg)
  • OGG — open format, good support (audio/ogg)
  • WAV — uncompressed, large size (audio/wav)

Multiple Formats Example

<audio controls>
  <source src="apple.mp3" type="audio/mpeg">
  <source src="apple.ogg" type="audio/ogg">
  Audio not supported in your browser.
</audio>

Fallback Content

Always include fallback text inside <audio> for older or unsupported browsers:

<audio controls>
  <source src="fruit.mp3" type="audio/mpeg">
  Your browser does not support this audio file. Try downloading it instead.
</audio>

Example: Full Audio Player

<h3>Listen to the Banana Song</h3>

<audio controls preload="auto">
  <source src="banana-theme.mp3" type="audio/mpeg">
  <source src="banana-theme.ogg" type="audio/ogg">
  Sorry, your browser doesn’t support this audio format.
</audio>
[ Audio player titled "Listen to the Banana Song" ]

Accessibility Tips

  • Always use controls so users can manage playback
  • Don’t use autoplay unless muted or critical
  • Provide descriptive context or labels for screen reader users

Summary

The <audio> tag turns your HTML page into a multimedia experience. You've learned how to:

  • Embed audio with fallback and multiple formats
  • Control playback with HTML attributes
  • Ensure accessibility and graceful degradation

What’s Next?

Next, let’s explore the <video> element — the natural visual companion to <audio>, perfect for tutorials, animations, and storytelling.

QUIZ

Question 1:What attribute of the <audio> tag allows users to control playback (play, pause, volume)?

Question 2:The autoplay attribute in the <audio> tag makes the audio start playing immediately when the page loads.

Question 3:Which of the following are valid audio file formats supported by most browsers for the <audio> tag?

Question 4:What does the loop attribute do when added to an <audio> element?

Question 5:It is good practice to include fallback text inside the <audio> tag for browsers that do not support the audio element.

Question 6:Which of the following attributes can be used with the <audio> tag to enhance user experience?