,

Audio in HTML – Media in HTML.

Posted by

HTML Audio – HTML Media

HTML Audio – HTML Media

HTML audio is a way to embed audio content on a webpage. The

Basic Audio Tag

To include audio on a webpage, you can use the


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

The “controls” attribute adds playback controls to the audio player, allowing users to play, pause, and adjust the volume of the audio file. If the browser does not support the

Audio File Formats

HTML audio supports various file formats, including MP3, WAV, and OGG. You can specify multiple audio sources within the


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

In this example, the browser will try to play the MP3 file first, and if it’s not supported, it will try the WAV and OGG files, in that order.

Audio Attributes

There are several attributes that can be used with the


<audio src="audiofile.mp3" autoplay>
Your browser does not support the audio element.
</audio>

The “loop” attribute causes the audio to play in a continuous loop, and the “preload” attribute specifies whether the audio file should be preloaded when the webpage loads.

HTML audio provides a simple and convenient way to add audio content to web pages without relying on third-party plugins or software. With the