HTML <audio> tag
When writing in HTML, the <audio> tag is an inline element used to embed sound files into a web page. It is useful when you want to add any audio, such as a song or interview, to your web pages. The following sections contain information about this tag, including an example of it in use, as well as related attributes and browser compatibility.
Your browser does not support the <audio> tag. <source src="https://www.computerhope.com/jargon/m/example.mp3" />
The above code, rendered in a web browser:
File formats and browser support
When utilizing the <audio> tag, you need to ensure that your sound file is in the proper format. There are three accepted formats which include MP3, Ogg, and WAV. The table below shows which Internet browsers support which file format.
Within an HTML tag, an attribute dictates certain aspects of an HTML element. Attributes are made up of a name and value pair; all tags support standard attributes. The following table shows all of the current unique HTML attributes for the <audio> tag, as well as a description of each.
|autoplay||Designates that the audio file will play immediately after it loads.|
|controls||Designates what controls to display with the audio player.|
|loop||Designates that the audio file should continuously repeat.|
|muted||Designates that the audio file should be muted.|
|preload||Designates how and when the audio file should load.|
|src||Designates the URL of the audio file.|