HTML Audio

HTML Audio

The <audio> element in HTML is used to embed audio content on web pages. It allows users to play, pause, and control audio directly in the browser without additional plugins.


Basic Syntax


 

  • <source> → Specifies the audio file and its format.

  • controls → Displays play, pause, and volume controls.

  • Fallback text is displayed if the browser does not support <audio>.


Audio Attributes

Attribute Description
controls Displays audio controls for the user
autoplay Starts playing the audio automatically
loop Plays the audio continuously
muted Starts the audio muted
preload Specifies how the audio should be loaded (auto, metadata, none)

Example: HTML Audio with Attributes


 

Explanation:

  • Audio starts autoplay, loops, and is muted by default.

  • Multiple <source> tags ensure cross-browser compatibility.

  • controls allows the user to play, pause, and adjust volume.


Key Points

  • HTML5 <audio> eliminates the need for Flash or external plugins.

  • Always include multiple audio formats (mp3, ogg, etc.) for compatibility.

  • Use controls for better user experience.

  • autoplay often requires muted to work in modern browsers.

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *