HTML Audio & Video
HTML DOM Audio controls Property
The controls property sets or returns whether a media element displays the browser's built-in playback controls such as play/pause, volume and the seek bar. It reflects the controls HTML attribute and is a boolean.
Definition and Usage
When controls is true the browser renders its native player UI over the media. When it is false you must supply your own custom controls in HTML and wire them to the media API with JavaScript.
The property returns true when the controls attribute is present, and setting it adds or removes that attribute, which shows or hides the native UI instantly.
Syntax
// Get the value
let shown = mediaElement.controls;
// Set the value
mediaElement.controls = false;Example
This runnable page toggles the native controls on and off and reports the current state. When they are hidden, the custom Play/Pause button still works.
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><title>controls Demo</title></head>
<body>
<h2>Show or hide the native controls</h2>
<video id="myVideo" width="320" controls>
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
<p>
<button onclick="toggleUI()">Toggle controls</button>
<button onclick="play()">Custom play/pause</button>
</p>
<p id="output"></p>
<script>
const video = document.getElementById("myVideo");
const out = document.getElementById("output");
function toggleUI() {
video.controls = !video.controls;
out.textContent = "controls = " + video.controls;
}
function play() {
if (video.paused) { video.play(); } else { video.pause(); }
}
</script>
</body>
</html>More Examples
For audio, hiding the controls turns the element invisible, so a custom button becomes the only way to play it.
<!DOCTYPE html>
<html>
<body>
<audio id="a">
<source src="https://www.w3schools.com/html/horse.mp3" type="audio/mpeg">
</audio>
<p>
<button onclick="a.play()">Play</button>
<button onclick="a.pause()">Pause</button>
<button onclick="show()">Show controls?</button>
</p>
<p id="msg"></p>
<script>
const a = document.getElementById("a");
function show() {
a.controls = true; // reveal the native player
document.getElementById("msg").textContent = "Native controls now visible.";
}
</script>
</body>
</html>If you hide the controls, make sure your custom UI is keyboard-accessible and exposes at least play/pause and volume, otherwise you harm accessibility.
Key Takeaways
- controls is a boolean reflecting the controls HTML attribute.
- true shows the browser's native player UI; false hides it.
- Toggling it lets you swap between native and custom controls.
- A media element with controls hidden is driven entirely from JavaScript.
- Always keep custom controls accessible when you hide the native ones.
