<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
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
|Content categories||Flow content, phrasing content, embedded content. If it has a
|Permitted content||If the element has a
Else: zero or more
|Tag omission||None, both the starting and ending tag are mandatory.|
|Permitted parents||Any element that accepts embedded content.|
|Permitted ARIA roles||
This element's attributes include the global attributes.
- A Boolean attribute: if specified, 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.
- An attribute you can read to determine which time ranges of the media have been buffered. This attribute contains a
- 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.
- A Boolean attribute: if specified, will automatically seek back to the start upon reaching the end of the audio.
- The offset, specified as the number of samples since the beginning of the audio stream, at which the audio is currently playing.
- A Boolean attribute which indicates whether the audio will be initially silenced. Its default value is
TimeRangesobject indicating all the ranges of the audio that have been played.
- 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
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
autoplayattribute has precedence over
autoplayis 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.
- 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.
- 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.
An audio element can fire various events.
Fallback content for browsers not supporting the
<audio> element can be added inside the opening and closing
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
Audio streams/Web Audio API
<audio> and subtitles
<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.
<!-- 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
<audio controls="controls"> <source src="foo.wav" type="audio/wav"> Your browser does not support the <code>audio</code> element. </audio>
<audio> with multiple
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>
Audio with spoken dialog should provide both captions and transcripts that accurately describe its content. Captions allow people who are experiencing hearing loss to understand an audio recording's content as the recording is being played, while transcripts allow people who need additional time to be able to review the recording's content at a pace and format that is comfortable for them.
If automatic captioning services are used, it is important to review the generated content to ensure it accurately represents the source audio.
In addition to spoken dialog, subtitles and transcripts should also identify music and sound effects that communicate important information. This includes emotion and tone:
1 00:00:00 --> 00:00:45 [Energetic techno music] 2 00:00:46 --> 00:00:51 Welcome to the Time Keeper's podcast! In this episode we're discussing which Swisswatch is a wrist switchwatch? 16 00:00:52 --> 00:01:02 [Laughing] Sorry! I mean, which wristwatch is a Swiss wristwatch?
- MDN Subtitles and closed caption - Plugins
- Web Video Text Tracks Format (WebVTT)
- WebAIM: Captions, Transcripts, and Audio Descriptions
- MDN Understanding WCAG, Guideline 1.2 explanations
- Understanding Success Criterion 1.2.1 | W3C Understanding WCAG 2.0
- Understanding Success Criterion 1.2.2 | W3C Understanding WCAG 2.0
|HTML Living Standard
The definition of '<audio>' in that specification.
The definition of '<audio>' in that specification.
3.5 — 42
10.5 — 152
|Feature||Android webview||Chrome for Android||Edge mobile||Firefox for Android||Opera Android||iOS Safari||Samsung Internet|
Yes — 152
1. For Firefox to play audio, the server must serve the file using the correct MIME type.
2. Supported as