HTML5 introduced the <audio>
element to include audio content directly in an HTML document. With the <audio>
element, you can play audio files, define multiple sources for different browsers, and provide fallback content in case the browser does not support the <audio>
element.
Example:
<audio controls>
<source src="music.mp3" type="audio/mp3">
<source src="music.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>
In Above example, the controls
attribute adds audio controls, such as play, pause, and volume, to the audio element. The <source>
element is used to provide different audio file formats for different browsers. The type
attribute specifies the MIME type of the audio file. The text inside the <audio>
element is fallback content that will be displayed if the browser does not support the <audio>
element.