Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

<audio>

Embeds an audio player.

Syntax

<audio src="file.mp3" controls></audio>

Attributes

ParameterTypeDescription
srcURLThe audio file address (or use `<source>`).
controls—Show the player. Without it the element is invisible.
loop—Optional. Play in a loop.
preloadnone | metadata | autoOptional. How much to load in advance.

Examples

A player with the standard controls:

<p>Listen to a T-rex:</p>
<audio src="/media/t-rex-roar.mp3" controls></audio>

A fallback for old browsers:

<audio controls preload="none">
  <source src="/media/t-rex-roar.mp3" type="audio/mpeg">
  <a href="/media/t-rex-roar.mp3">Download the sound</a>
</audio>

Notes

Without controls the player is invisible and sound can only be started from JavaScript. The standard player looks different in each browser and can hardly be styled with CSS.

See also

  • <video> — Embeds a video in the page.
  • <source> — One of the file versions for `<video>`, `<audio>` or `<picture>`.

Related recipes

In the tutorial

  • Audio and video — The video and audio tags, the controls panel, autoplay, looping, several formats with source and subtitles.

Thanks for reading!

Donate to the site — we work hard for you.