HTML Audio

HTML Tutorial

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

AttributeDescription
controlsDisplays audio controls for the user
autoplayStarts playing the audio automatically
loopPlays the audio continuously
mutedStarts the audio muted
preloadSpecifies 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.

You may also like...