Images & Media

HTML <audio> element

Embeds sound. controls exposes native playback controls; autoplay may be blocked by browser policy. Provide a transcript for meaningful spoken content. The example uses illustrative local asset paths; supply matching files before running it. Provide playback controls and a text alternative or transcript when appropriate. Browser support for audio codecs differs from support for the audio element itself. Do not assume autoplay is allowed. It accepts global HTML attributes; individual global features may be inapplicable or restricted.

Formal Syntax & Structure

html syntaxhtml
<audio controls src="sample.ogg"></audio>

Parameters & Attributes

NameTypeDescription
srcURLSpecifies the resource to load for the given element, such as an image, script or media file. The resource type, loading behavior and security rules depend on the element.
crossoriginenumerated: anonymous, use-credentialsConfigures CORS settings for eligible resource requests. anonymous omits cross-origin credentials; use-credentials includes them. Server CORS headers must permit the request when needed.
preloadenumerated: none, metadata, autoHints how much audio or video data should be fetched before playback. Browsers may ignore this hint; autoplay can take precedence.
autoplaybooleanRequests that media begin playback without a manual play action. Browsers may block it, especially for audible media; provide controls.
loopbooleanRequests media replay after reaching the end. The effect depends on media playback and user settings; provide controls for stopping repeated content.
mutedbooleanSets the default muted state of a media element. The current muted state can change via user controls or JavaScript. Muted autoplay may still be restricted.
controlsbooleanRequests native playback controls for audio or video. It is a boolean attribute; controls="false" still enables it. Provide accessible alternatives if implementing custom controls.

Return Value

HTMLAudioElement

Content model: Source elements when no src is supplied, optional tracks and fallback content; no nested audio or video.

Working Example

Example Snippethtml
<!doctype html><html lang="en">  <head>    <meta charset="utf-8">    <title>HTML example</title>  </head>  <body>    <audio controls src="sample.ogg">Audio unavailable.</audio>    <p>Transcript: Welcome to the guide.</p>  </body></html>
HTML Reference