HTML <audio>
Represents an interface for adding audio content to the page.
HTML supports the following audio formats:
- MP3
- WAV
- OGG
Syntax
<audio controls><!-- Source tags with different audio formats go here --></audio>
The <audio> element may contain one or more <source> elements with different audio formats. The browser will run the format most suitable for the browser.
The <audio> tag may include <source> tags and fallback text. It may also use attributes to convey intention, such as the ones listed below:
- Using
autoplayautomatically plays the audio. - Using
controlshas an overlay to allow the user to control the audio. - Using
loopspecifies that when the audio ends, it will begin again. - Setting
srcto the URL for the audio to be shown to the user.
Example
<audio controls><source src="audioFile_name.ogg" type="audio/ogg" /><source src="audioFile_name.mp3" type="audio/mpeg" /><h3>Fallback text if audio will not play</h3></audio>

In the example above, the <audio> element contains the controls attribute to display user controls for the audio content such as a play and pause button. In addition, there are two <source> tags with different audio formats. If the browser doesn’t support the .ogg file format, it will use the .mp3 file. Lastly, the text that follows the <source> tags will display if the <audio> tag is not supported by the browser.
Learn HTML on Codecademy
- Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
- Includes 34 Courses
- With Professional Certification
- Beginner Friendly.115 hours
- Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.
- Beginner Friendly.7 hours