audio – audio
<audio src="sound.mp3" controls></audio>
Sound played by the browser: music, a podcast, the pronunciation of a word. With the controls attribute it shows the controls, without it it is invisible and a script controls playback. The attributes are the same as for video, except the visual ones (poster, width, height, playsinline).
- Default display:
display: nonewithoutcontrols; with them the controls are shown - End tag: required
- Content:
source,trackand fallback content - Where it can be used: anywhere phrasing content is allowed
- DOM interface:
HTMLAudioElement
Attributes
- src – the URL of the file (or
sourceelements). - controls – the browser’s controls.
- autoplay, loop, muted – automatic start (browsers mostly block it with sound), repeating, muting.
- preload –
none,metadata,auto. - crossorigin – loading via CORS (needed for processing the sound with the Web Audio API).
Examples
A podcast with controls and a download link:
<audio controls preload="metadata"> <source src="/audio/episode-12.mp3" type="audio/mpeg"> <a href="/audio/episode-12.mp3">Download episode 12 (MP3)</a> </audio>
A sound played by a script after a click:
<audio id="bell" src="/audio/bell.mp3" preload="auto"></audio>
<button type="button" onclick="document.getElementById('bell').play()">Ring the bell</button>
Accessibility
Add a transcript as text on the page for speech (a podcast, an interview). Sound that starts by itself interferes with screen readers – leave starting it to the user.
Things to watch out for
- The height and look of the controls are set by the browser and look different in each one. The width can be set in CSS, a custom look only with custom controls in JavaScript.
play()returns a Promise – when the browser blocks playback (without a click from the user), it ends with an error that is worth catching.- All current browsers play MP3, so there is no need to offer another format.
Browser support
Baseline – widely available: works in all major browsers and has for a long time (since 2015 at the latest). Since version: Chrome 3, Firefox 3.5, Safari 3.1. As of October 2026 (MDN browser-compat-data).
Related:
video – video
source – image or media source
track – subtitles
button – button