💡 Tip: Login now to track your course progress and unlock your downloadable certificates instantly!

HTML Audio

HTML allows you to add audio content directly to web pages using the <audio> element. You can embed music, podcasts, sound effects, or any audio file without relying on third-party plugins. The <audio> element supports multiple audio formats, offers controls, and can play automatically or loop based on your settings.

HTML <audio> Syntax

Audio Example
<audio controls>
  <source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" type="audio/mpeg">
  <source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.ogg" type="audio/ogg">
  Your browser does not support the audio element.
</audio>

Explanation

  • <audio>: The container element for audio files.
  • controls: Adds play, pause, volume, and other standard audio controls.
  • <source>: Specifies the audio file and its type. Multiple sources ensure compatibility across browsers.
  • Fallback text: Displayed if the browser doesn’t support the <audio> element.

Attributes of <audio>

  • controls: Shows audio player controls.
  • autoplay: Starts playing automatically when the page loads.
  • loop: Replays audio continuously.
  • muted: Starts audio in a muted state.
  • preload: Specifies whether to load audio data (auto, metadata, none).

Example with attributes:

HTML Audio Attributes
<audio controls autoplay loop>
  <source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

Supported Audio Formats

  1. MP3 — widely supported.
  2. OGG — open-source alternative.
  3. WAV — uncompressed audio, large file size.

⚠️ Tip: Always provide multiple formats for maximum browser compatibility.

Example: Complete HTML Audio Player

Complete HTML Audio Example
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>HTML Audio Example</title>
</head>
<body>

<h2>Listen to Our Audio Track</h2>
<audio controls>
  <source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" type="audio/mpeg">
  <source src="https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.ogg" type="audio/ogg">
  Your browser does not support the audio element.
</audio>

<p>Enjoy the music directly from your browser without any plugins!</p>

</body>
</html>

Advantages

  • Embed audio without third-party plugins.
  • Cross-browser compatibility with multiple source formats.
  • Easy to control playback with attributes like autoplay, loop, and controls.
  • Improves interactivity and engagement on web pages.

Conclusion

The HTML <audio> element makes adding sound to your website simple and efficient.
By using multiple sources and the built-in controls, you can ensure your audio plays seamlessly across all modern browsers. Whether it’s background music, podcasts, or alerts, <audio> enhances the user experience without extra plugins.

Sign In Form

User your email and password to singn in

Don’t have an account, signup here : 

HTML5 & CSS3

Tools and Tutorials

Want a Website

Want a website for your business ?

Please fill out the details below, so we can reach out to you.

Registration Form

Signup to track your record and much more.

We have sent you an email with a registration link. Please click the link to verify your email address, or enter the 6-digit OTP provided in the email.

Didn't receive the OTP. Regenerate OTP Resend