HTML Audio

The HTML <audio> tag is used to embed sound files such as music and other audio clips into a web page. HTML5 provides native support for audio playback without the need for additional plugins like Flash or Silverlight.

Supported Audio Formats:

MP3: The most widely supported audio format.

WAV: A raw audio format that is uncompressed

OGG: A compressed audio format with better compression than MP3.

Example:

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

Attribute Description
src Specifies the path to the audio file to be played. This attribute is used to define the source of the audio content.
controls Adds play, pause, and volume controls to the audio player. This attribute is boolean; if present, the controls will be displayed.
autoplay If present, the audio will automatically start playing as soon as it is loaded.
loop If present, the audio will loop continuously once it finishes playing.
muted If present, the audio will be muted by default.
preload Specifies if and how the audio file should be preloaded when the page loads. Possible values are:
  • auto: The browser may preload the entire audio file.
  • metadata: Only metadata (e.g., duration) will be preloaded.
  • none: The audio file will not be preloaded.