<audio>: The Embed Audio element

The HTML <audio> element is used to embed sound content in documents. It may contain one or more audio sources, represented using the src attribute or the <source> element: the browser will choose the most suitable one. It can also be the destination for streamed media, using a MediaStream.

Summary

 
Content categories Flow content, phrasing content, embedded content. If it has a controls attribute: interactive content and palpable content.
Permitted content If the element has a src attribute: zero or more <track> elements followed by transparent content that contains no <audio> or <video> media elements.
Else: zero or more <source> elements followed by zero or more <track> elements followed by transparent content that contains no <audio> or <video> media elements.
Tag omission None, both the starting and ending tag are mandatory.
Permitted parents Any element that accepts embedded content.
Permitted ARIA roles application
DOM interface HTMLAudioElement

Attributes

This element's attributes include the global attributes.

autoplay
A Boolean attribute: if specified (even if the value is "false"!), the audio will automatically begin playback as soon as it can do so, without waiting for the entire audio file to finish downloading.
Sites which automatically play audio (or videos with an audio track) can be an unpleasant experience for users, so it should be avoided when possible. If you must offer autoplay functionality, you should make it opt-in (requiring a user to specifically enable it). However, this can be useful when creating media elements whose source will be set at a later time, under user control.
buffered
An attribute you can read to determine which time ranges of the media have been buffered. This attribute contains a TimeRanges object.
controls
If this attribute is present, the browser will offer controls to allow the user to control audio playback, including volume, seeking, and pause/resume playback.
loop
A Boolean attribute: if specified, will automatically seek back to the start upon reaching the end of the audio.
mozCurrentSampleOffset
The offset, specified as the number of samples since the beginning of the audio stream, at which the audio is currently playing.
muted
A Boolean attribute which indicates whether the audio will be initially silenced. Its default value is false.
played
A TimeRanges object indicating all the ranges of the audio that have been played.
preload
This enumerated attribute is intended to provide a hint to the browser about what the author thinks will lead to the best user experience. It may have one of the following values:
  • none: indicates that the audio should not be preloaded;
  • metadata: indicates that only audio metadata (e.g. length) is fetched;
  • auto: indicates that the whole audio file could be downloaded, even if the user is not expected to use it;
  • the empty string: synonym of the auto value.

If not set, its default value is browser-defined (i.e. each browser may have its own default value). The spec advises it to be set to metadata.

Usage notes:
  • The autoplay attribute has precedence over preload. If autoplay is specified, the browser would obviously need to start downloading the audio for playback.
  • The browser is not forced by the specification to follow the value of this attribute; it is a mere hint.
src
The URL of the audio to embed. This is subject to HTTP access controls. This is optional; you may instead use the <source> element within the audio block to specify the audio to embed.
volume
The playback volume, in the range 0.0 (silent) to 1.0 (loudest).

Time offsets are specified as float values indicating the number of seconds to offset.

Note: The time offset value definition has not yet been completed in the HTML5 specification and is subject to change.

Events

An audio element can fire various events.

Usage notes

Basics

Fallback content for browsers not supporting the <audio> element can be added inside the opening and closing <audio></audio> tags.

The most basic playback functionality can be made available using the controls attribute (see Examples below); for more advanced usage, audio playback and controls can be manipulated using the HTML Media API, and more specifically the features defined in the HTMLAudioElement interface.

Audio streams/Web Audio API

You can also use the Web Audio API to directly generate and manipulate audio streams from JavaScript code. See Web Audio API for details.

<audio> and subtitles

While HTML5 <video> can have subtitles included via the <track> element (see Adding captions and subtitles to HTML5 video), <audio> elements can't — any <track> elements included within <audio></audio> tags are just ignored. See WebVTT and Audio by Ian Devlin for some more useful information and workarounds.

Examples

Basic usage

<!-- Simple audio playback -->
<audio
  src="http://developer.mozilla.org/@api/deki/files/2926/=AudioTest_(1).ogg"
  autoplay>
  Your browser does not support the <code>audio</code> element.
</audio>

<audio> element with <source> element

<audio controls="controls">
  Your browser does not support the <code>audio</code> element.
  <source src="foo.wav" type="audio/wav">
</audio>

<audio> with multiple <source> elements

The browser tries to load the first source element (Opus) if it is able to play it, if not falls back to the second (vorbis) and finally back to mp3:

<audio controls="">
 <source src="foo.opus" type="audio/ogg; codecs=opus"/>
 <source src="foo.ogg" type="audio/ogg; codecs=vorbis"/>
 <source src="foo.mp3" type="audio/mpeg"/>
</audio>

Specifications

Specification Status Comment
HTML Living Standard
The definition of '<audio>' in that specification.
Living Standard  
HTML5
The definition of '<audio>' in that specification.
Recommendation  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
audioChrome Full support 3Edge Full support YesFirefox Full support 3.5
Notes
Full support 3.5
Notes
Notes For Firefox to play audio, the server must serve the file using the correct MIME type.
IE Full support 9Opera Full support 10.5Safari Full support 3.1WebView Android Full support 3Chrome Android Full support 18Firefox Android Full support 4
Notes
Full support 4
Notes
Notes For Firefox to play audio, the server must serve the file using the correct MIME type.
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
autoplayChrome Full support 3Edge Full support YesFirefox Full support 3.5IE Full support 9Opera Full support 10.5Safari Full support 3.1WebView Android Full support 3Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
bufferedChrome ? Edge Full support YesFirefox Full support 4IE ? Opera ? Safari ? WebView Android ? Chrome Android ? Firefox Android Full support 4Opera Android ? Safari iOS ? Samsung Internet Android ?
controlsChrome Full support 3Edge Full support YesFirefox Full support 3.5IE Full support 9Opera Full support 10.5Safari Full support 3.1WebView Android Full support 3Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
loopChrome Full support 3Edge Full support YesFirefox Full support 11IE Full support 9Opera Full support 10.5Safari Full support 3.1WebView Android Full support 3Chrome Android Full support 18Firefox Android Full support 14Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
mozcurrentsampleoffset
Non-standard
Chrome No support NoEdge No support NoFirefox Full support 3.5IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android Full support 4Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
mutedChrome ? Edge Full support YesFirefox Full support 11IE ? Opera ? Safari ? WebView Android ? Chrome Android ? Firefox Android Full support 14Opera Android ? Safari iOS ? Samsung Internet Android ?
playedChrome Full support 49Edge Full support 14Firefox Full support 15IE Full support 11Opera Full support 46Safari Full support 9.1WebView Android Full support 49Chrome Android Full support 49Firefox Android Full support 15Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 5.0
preloadChrome Full support 3
Notes
Full support 3
Notes
Notes Defaults to metadata in Chrome 64.
Edge Full support YesFirefox Full support 4
Full support 4
No support 3.5 — 4
Alternate Name
Alternate Name Uses the non-standard name: autobuffer
IE Full support 9Opera Full support 15
Notes
Full support 15
Notes
Notes Defaults to metadata in Opera 51.
No support 10.5 — 15
Alternate Name
Alternate Name Uses the non-standard name: autobuffer
Safari Full support 3.1WebView Android Full support 3
Notes
Full support 3
Notes
Notes Defaults to metadata in Chrome 64.
Chrome Android Full support 18
Notes
Full support 18
Notes
Notes Defaults to metadata in Chrome 64.
Firefox Android Full support 4Opera Android Full support 14
Notes
Full support 14
Notes
Notes Defaults to metadata in Opera 51.
No support ? — 14
Alternate Name
Alternate Name Uses the non-standard name: autobuffer
Safari iOS Full support YesSamsung Internet Android Full support Yes
srcChrome Full support 3Edge Full support YesFirefox Full support 3.5IE Full support 9Opera Full support 10.5Safari Full support 3.1WebView Android Full support 3Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
volumeChrome ? Edge Full support YesFirefox ? IE ? Opera ? Safari ? WebView Android ? Chrome Android ? Firefox Android ? Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
See implementation notes.
See implementation notes.
Uses a non-standard name.
Uses a non-standard name.

See also