The HTML element is used to play an audio file on a web page.
The HTML Element
To play an audio file in HTML, use the element:
Example
Your browser does not support the audio element.
Try it Yourself »
HTML Audio - How It Works
The controls
attribute adds audio controls, like play, pause, and volume.
The element allows you to specify alternative audio files which the browser may choose from. The browser will use the first recognized format.
The text between the and
tags will only be displayed in browsers that do not
support the
element.
HTML Autoplay
To start an audio file automatically, use the autoplay
attribute:
Example
Your browser does not support the audio element.
Try it Yourself »
Note: Chromium browsers do not allow autoplay in most cases. However, muted autoplay is always allowed.
Add muted
after
autoplay
to let your audio file start playing automatically [but muted]:
Example
Your browser does not support the audio element.
Try it Yourself »
Browser Support
The numbers in the table specify the first browser version that fully supports the element.
4.0 | 9.0 | 3.5 | 4.0 | 10.5 |
HTML Audio Formats
There are three supported audio formats: MP3, WAV, and OGG. The browser support for the different formats is:
Edge/IE | YES | YES* | YES* |
Chrome | YES | YES | YES |
Firefox | YES | YES | YES |
Safari | YES | YES | NO |
Opera | YES | YES | YES |
*From Edge 79
HTML Audio - Media Types
MP3 | audio/mpeg |
OGG | audio/ogg |
WAV | audio/wav |
HTML Audio - Methods, Properties, and Events
The HTML DOM defines methods, properties, and events for the element.
This allows you to load, play, and pause audios, as well as set duration and volume.
There are also DOM events that can notify you when an audio begins to play, is paused, etc.
For a full DOM reference, go to our HTML Audio/Video DOM Reference.
HTML Audio Tags
Defines sound content | |
Defines multiple media resources for media elements, such as and |
❮ Audio Object
Example
An audio player with play and pause buttons:
var x = document.getElementById["myAudio"];
function playAudio[] {
x.play[];
}
function pauseAudio[] {
x.pause[];
}
Try it Yourself »
Definition and Usage
The play[] method starts playing the current audio.
Tip: This method is often used together with the pause[] method.
Tip: Use the controls property to display audio controls [like play, pause, seeking, volume, etc, attached on the audio].
Browser Support
play[] | Yes | 9.0 | Yes | Yes | Yes |
Syntax
Parameters
Return Value
❮ Audio Object
Example
Play a sound file:
Your browser does not support the audio tag.
Try it Yourself »
Definition and Usage
The tag is used to embed sound
content in a document, such as music or other audio streams.
The tag contains one or more
tags with different audio sources. The browser will choose the first source it supports.
The text between the and
tags will only be displayed in browsers that do not support the
element.
There are three supported audio formats in HTML: MP3, WAV, and OGG.
Audio Format and Browser Support
Edge / IE | YES | YES* | YES* |
Chrome | YES | YES | YES |
Firefox | YES | YES | YES |
Safari | YES | YES | NO |
Opera | YES | YES | YES |
*From Edge 79
Tips and Notes
Tip: For video files, look at the
tag.
Browser Support
The numbers in the table specify the first browser version that fully supports the element.
4.0 | 9.0 | 3.5 | 4.0 | 11.5 |
Attributes
autoplay | autoplay | Specifies that the audio will start playing as soon as it is ready |
controls | controls | Specifies that audio controls should be displayed [such as a play/pause button etc] |
loop | loop | Specifies that the audio will start over again, every time it is finished |
muted | muted | Specifies that the audio output should be muted |
preload | auto metadata none | Specifies if and how the author thinks the audio should be loaded when the page loads |
src | URL | Specifies the URL of the audio file |
Global Attributes
The tag also supports the Global Attributes in HTML.
Event Attributes
The tag also supports the Event Attributes in HTML.
Related Pages
HTML DOM reference: HTML Audio/Video DOM Reference
Default CSS Settings
None.