👀 Live Preview
Video with browser default controls:

The controls attribute is a valuable feature in HTML that lets developers enhance the user interface of multimedia elements such as <video> and <audio>. By adding controls, you give users built-in playback controls so they can play, pause, seek, and adjust volume without writing custom JavaScript UI code.
Present = on.
Media elements.
Play, pause, volume.
JS property.
When to hide UI.
Always offer control.
controlsThe primary purpose of the controls attribute is to show or hide the browser’s default user interface for multimedia elements. When the attribute is present, users can play, pause, scrub the timeline, adjust volume, and perform other playback actions directly from the embedded media player.
A <video> or <audio> element without controls can still play programmatically (for example with autoplay or JavaScript play()), but users have no visible way to pause or adjust volume unless you build custom controls.
Add the boolean controls attribute to a media element:
<video controls width="640" height="360">
<source src="clip.mp4" type="video/mp4">
</video>
<audio controls src="song.mp3"></audio>controls (not controls="controls").element.controls (boolean property).The controls attribute is a boolean attribute. It does not use meaningful string values like "true" or "false" in HTML markup:
controls or controls="".Writing controls="false" in HTML still shows controls because the attribute is present. To disable controls, remove the attribute or set element.controls = false in JavaScript.
<!-- Shows controls -->
<video controls src="clip.mp4"></video>
<!-- Hides controls (no attribute) -->
<video src="clip.mp4"></video>
<!-- JavaScript toggle -->
<script>
videoElement.controls = false;
</script>| Goal | Markup / Code | Result |
|---|---|---|
| Show controls | <video controls> | Browser default UI visible |
| Hide controls | <video src="..."> | No default UI |
| Audio controls | <audio controls> | Play bar with timeline |
| Enable with JS | el.controls = true | Show controls at runtime |
| Disable with JS | el.controls = false | Hide default UI |
| Check state | el.controls | Returns true or false |
| Element | Supported? | Notes |
|---|---|---|
<video> | Yes | Play, pause, timeline, fullscreen (browser-dependent) |
<audio> | Yes | Compact audio bar with play and volume |
<iframe> | No | Use embed provider’s own controls |
<img> | No | Not a media element |
| Feature | controls attribute | Custom JavaScript player |
|---|---|---|
| Setup effort | One attribute | HTML, CSS, and JS required |
| Look and feel | Browser-native styling | Fully brandable |
| Accessibility | Built-in keyboard support | You must implement ARIA and keys |
| Best for | Tutorials, blogs, simple embeds | Streaming apps, branded players |
Video with controls, JavaScript toggle, and audio with controls.
Video with browser default controls:
Let’s look at a simple example of how to use the controls attribute for an HTML <video> element:
<video controls width="400" height="300">
<source src="example.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>In this example, the controls attribute enables the default video player controls so users can play, pause, and adjust volume without extra code.
Similar to other HTML attributes, you can dynamically set the controls property using JavaScript. This is useful when you want to show controls only after a user action or switch between a minimal and full player UI:
<button type="button" id="toggleBtn">Show Controls</button>
<video id="dynamicVideo" width="320" height="240" src="example.mp4"></video>
<script>
var video = document.getElementById("dynamicVideo");
var btn = document.getElementById("toggleBtn");
btn.addEventListener("click", function () {
video.controls = !video.controls;
btn.textContent = video.controls ? "Hide Controls" : "Show Controls";
});
</script>In this script, clicking the button toggles the controls property on a video element with the id dynamicVideo. Setting video.controls = true shows the browser UI; setting it to false hides it.
The controls attribute works the same way on <audio> elements:
<audio controls>
<source src="song.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>Adding controls to <audio> displays a compact playback bar. Provide multiple <source> elements so different browsers can pick a supported format.
controls is the simplest path.<track kind="captions"> for video accessibility; controls alone are not enough for deaf users.autoplay with controls so users can stop unexpected playback.Mark a video or audio element with the boolean attribute.
Play button, timeline, volume, and other native widgets appear.
Play, pause, seek, and volume changes update media state.
Users control playback without custom JavaScript UI code.
The controls attribute is supported in all modern browsers on <video> and <audio>. Control appearance varies slightly by browser and operating system.
All major browsers honor controls on media elements.
Bottom line: Use controls confidently for standard video and audio embeds; test styling if you combine it with custom CSS.
controls property for dynamic show/hide behavior<track> for accessible videocontrols="false" hides controls in HTML markupcontrols attribute when you want a standard set of playback controls for multimedia elements.The controls attribute is a valuable tool for enhancing the usability of multimedia elements in HTML. By utilizing this attribute, you can provide users with a familiar and convenient way to interact with audio and video content embedded in your web pages.
For most sites, adding controls is the fastest path to a usable media player. When you need a branded experience, hide default controls and build custom UI—but always preserve pause, mute, and keyboard access.
controlsBookmark these before embedding media on your pages.
Present = show UI.
SyntaxMedia only.
ScopeJS toggle.
ScriptRemove attr.
GotchaPause always.
A11y<video> and <audio> elements so users can play, pause, seek, and adjust volume.controls from the markup or set element.controls = false in JavaScript.<video> and <audio> only. It is not valid on images, divs, or iframes.videoElement.controls = true or false. You can also use setAttribute('controls', '') and removeAttribute('controls').Practice the controls attribute with live video, audio, and JavaScript toggle examples in the Try It editor.
3 people found this page helpful