HTML controls Attribute

Beginner
⏱️ 4 min read
📚 Updated: Jun 2026
🎯 3 Examples
Media

Introduction

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.

What You’ll Learn

01

Boolean Attr

Present = on.

02

video & audio

Media elements.

03

Default UI

Play, pause, volume.

04

controls

JS property.

05

Custom Player

When to hide UI.

06

A11y & UX

Always offer control.

Purpose of controls

The 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.

💡
Without controls, media is still there

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.

📝 Syntax

Add the boolean controls attribute to a media element:

controls.html
<video controls width="640" height="360">

  <source src="clip.mp4" type="video/mp4">

</video>



<audio controls src="song.mp3"></audio>

Syntax Rules

  • Boolean attribute: if present, default controls are shown.
  • Modern HTML uses the bare attribute name: controls (not controls="controls").
  • Omit the attribute entirely to hide the default UI.
  • JavaScript uses element.controls (boolean property).

💎 Values

The controls attribute is a boolean attribute. It does not use meaningful string values like "true" or "false" in HTML markup:

  • Attribute present — Default playback controls are shown. Examples: controls or controls="".
  • Attribute absent — No default controls. Users cannot interact unless you provide custom UI or script-driven playback.
⚠️
Common mistake

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.

controls-boolean.html
<!-- Shows controls -->

<video controls src="clip.mp4"></video>



<!-- Hides controls (no attribute) -->

<video src="clip.mp4"></video>



<!-- JavaScript toggle -->

<script>

  videoElement.controls = false;

</script>

⚡ Quick Reference

GoalMarkup / CodeResult
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 JSel.controls = trueShow controls at runtime
Disable with JSel.controls = falseHide default UI
Check stateel.controlsReturns true or false

Applicable Elements

ElementSupported?Notes
<video>YesPlay, pause, timeline, fullscreen (browser-dependent)
<audio>YesCompact audio bar with play and volume
<iframe>NoUse embed provider’s own controls
<img>NoNot a media element

Default controls vs custom player

Featurecontrols attributeCustom JavaScript player
Setup effortOne attributeHTML, CSS, and JS required
Look and feelBrowser-native stylingFully brandable
AccessibilityBuilt-in keyboard supportYou must implement ARIA and keys
Best forTutorials, blogs, simple embedsStreaming apps, branded players

Examples Gallery

Video with controls, JavaScript toggle, and audio with controls.

👀 Live Preview

Video with browser default controls:

Example

Let’s look at a simple example of how to use the controls attribute for an HTML <video> element:

controls.html
<video controls width="400" height="300">

  <source src="example.mp4" type="video/mp4">

  Your browser does not support the video tag.

</video>
Try It Yourself

How It Works

In this example, the controls attribute enables the default video player controls so users can play, pause, and adjust volume without extra code.

Dynamic Values with JavaScript

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:

dynamic-controls.html
<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>
Try It Yourself

How It Works

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.

Audio Example

The controls attribute works the same way on <audio> elements:

audio-controls.html
<audio controls>

  <source src="song.mp3" type="audio/mpeg">

  Your browser does not support the audio element.

</audio>
Try It Yourself

How It Works

Adding controls to <audio> displays a compact playback bar. Provide multiple <source> elements so different browsers can pick a supported format.

♿ Accessibility

  • Always offer control — If media can play, users need a way to pause, mute, or stop it. Default controls is the simplest path.
  • Keyboard access — Browser-native controls support keyboard interaction; custom players must replicate that behavior.
  • Captions and transcripts — Use <track kind="captions"> for video accessibility; controls alone are not enough for deaf users.
  • Autoplay caution — Pair autoplay with controls so users can stop unexpected playback.
  • Visible focus — Do not hide native controls with CSS in ways that remove focus indicators users rely on.

🧠 How controls Works

1

Author adds controls

Mark a video or audio element with the boolean attribute.

Markup
2

Browser renders media UI

Play button, timeline, volume, and other native widgets appear.

UI
3

User interacts

Play, pause, seek, and volume changes update media state.

Playback
=

Accessible media experience

Users control playback without custom JavaScript UI code.

Browser Support

The controls attribute is supported in all modern browsers on <video> and <audio>. Control appearance varies slightly by browser and operating system.

HTML5 · Fully supported

Universal media controls

All major browsers honor controls on media elements.

99% Browser support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
controls attribute 99% supported

Bottom line: Use controls confidently for standard video and audio embeds; test styling if you combine it with custom CSS.

💡 Best Practices

✅ Do

  • Include controls on user-facing video and audio unless you build equivalent custom UI
  • Provide multiple source formats for broader compatibility
  • Pair autoplay with controls so users can stop playback
  • Use JavaScript controls property for dynamic show/hide behavior
  • Add captions with <track> for accessible video

❌ Don’t

  • Assume controls="false" hides controls in HTML markup
  • Remove controls without giving users another way to pause media
  • Hide native controls with CSS while leaving autoplay enabled
  • Rely on controls alone for full accessibility (add transcripts/captions)
  • Forget server-side validation of uploaded media files
  • Use the controls attribute when you want a standard set of playback controls for multimedia elements.
  • Consider omitting default controls only if you plan to implement a custom multimedia player with JavaScript.
  • Always ensure your multimedia files are in widely supported formats for a consistent user experience across browsers.

Conclusion

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.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about controls

Bookmark these before embedding media on your pages.

5
Core concepts
🎧 02

video & audio

Media only.

Scope
⚙️ 03

el.controls

JS toggle.

Script
⚠️ 04

No false in HTML

Remove attr.

Gotcha
05

User Control

Pause always.

A11y

❓ Frequently Asked Questions

It displays the browser’s built-in playback controls on <video> and <audio> elements so users can play, pause, seek, and adjust volume.
No. In HTML, any present boolean attribute enables the feature. Remove controls from the markup or set element.controls = false in JavaScript.
<video> and <audio> only. It is not valid on images, divs, or iframes.
Assign videoElement.controls = true or false. You can also use setAttribute('controls', '') and removeAttribute('controls').
Yes. If media starts automatically, users still need an obvious way to pause or mute it. Default controls satisfy that requirement.
Yes in all modern browsers. The exact look of the control bar may differ between Chrome, Firefox, Safari, and Edge.

Add playback controls to your media

Practice the controls attribute with live video, audio, and JavaScript toggle examples in the Try It editor.

Try video controls example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

3 people found this page helpful