DOM Properties

HTMLMediaElement.volume

Controls audio volume between 0 and 1, independently of muted. Out-of-range values throw. Some devices restrict programmatic volume changes. The numeric setting is independent of muted: volume=0 produces silence without necessarily setting muted. It is a setting on this media element rather than a device-wide volume control. The example only verifies the property value. Example result: 0.5.

Formal Syntax & Structure

html syntaxhtml
media.volume

Return Value

number

Number in the inclusive range 0 to 1; writable.

Working Example

Example Snippethtml
<p>  Result:  <output id="result"></output></p><script>  const result = document.getElementById("result");  (async () => {  const media = document.createElement("audio"); document.body.append(media);  result.textContent = (media.volume = 0.5, media.volume);  })().catch(error => { result.textContent = "Error: " + error.name; });</script>
HTML Reference