Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

HTML element: audio

The audio element embeds a sound resource and exposes the browser’s source-selection, buffering, timing, and playback model.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<audio controls preload="metadata" src="sound.wav"></audio>

audio can use one src or contain ordered source candidates; optional type, when supplied, helps the browser skip unsupported formats. Child fallback is only for browsers lacking the element, not an accessibility alternative or transcript in browsers that support audio.

controls exposes native controls, preload is only a hint, and autoplay can be blocked; muted and loop alter initial muting and repetition.

play() returns a Promise that policy or resource failure can reject; pause() stops playback, and currentTime seeks when the media is ready.

The example waits for loadedmetadata on an embedded WAV and reads duration, paused, and the resolved currentSrc without starting sound.

Examples

<!doctype html>
<meta charset="utf-8">
<audio id="clip" controls preload="metadata" src="data:audio/wav;base64,UklGRiwAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQgAAACAgICAgICAgA=="></audio>
<output id="result"></output>
<script>
const clip = document.querySelector("#clip");
clip.addEventListener("loadedmetadata", () => {
  document.querySelector("#result").textContent = `duration=${clip.duration.toFixed(3)}; paused=${clip.paused}; controls=${clip.controls}; source=${clip.currentSrc.startsWith("data:audio/wav")}`;
}, { once: true });
</script>

Result

duration=0.001; paused=true; controls=true; source=true

The result verifies loaded metadata, native controls, and the selected source; it does not prove audible playback or autoplay permission.

Sources