References

Beginner-friendly references for web development, with live, editable examples.

The HTML controls attribute

Attribute All modern browsers Updated
In short

The HTML controls attribute tells the browser to show its own playback controls on an <audio> or <video> element. It is a boolean attribute, so writing controls is enough. Without it, the browser is not asked to draw its controls, although it may still offer some in a context menu.

Overview

The controls attribute asks the browser to draw its own playback interface on a media element. It is a boolean attribute of <video> and <audio>, and the HTML Standard reads its presence as a sign that the author has not built a scripted controller and wants the browser's controls instead.

The standard also lists what those controls should cover. That means play and pause, seeking, volume, captions and sign-language tracks, audio track choices, and a way to watch in fullscreen or a separate resizable window. Each browser draws its own version, so the exact buttons and their look differ between engines.

Leaving controls off has the biggest effect on <audio>. The rendering rules tell browsers to force an audio element that exposes no interface to display: none, whatever your CSS says, so it takes no space and the listener has nothing to click.

On video, the poster image or the first frame still shows without the attribute, but play, pause and seek then have to come from your own buttons. Browsers may still offer a few controls through a context menu or media keys, and the standard says they should show the full interface when scripting is disabled.

Syntax

<video src="tour.mp4" controls width="640" height="360"></video>
<audio src="podcast.mp3" controls></audio>

Values

Value
A boolean attribute: present or absent.

Example

Live example
<video src="https://codeshack.io/web/example.mp4" controls width="150"></video>
<video src="https://codeshack.io/web/example.mp4" width="150"></video>
<p>The first video has controls. The second has none, so the page offers no button to start it.</p>

Best practices

  • Add controls to every <audio> element unless you build your own player, because an audio element without an interface is not rendered at all.
  • Keep controls on video that uses autoplay, so viewers can pause the motion and switch the sound on or off.
  • If you replace the native interface, use real <button> elements with clear names for play, pause and mute, and make sure they all work from the keyboard.
  • Test the native controls in every browser you support, since each engine draws its own buttons and menus.
  • Treat controlslist as an optional extra, because MDN's compatibility data lists it as unsupported in Firefox and Safari.

Accessibility

The controls attribute gives users the pause and volume mechanisms that WCAG expects. Success criterion 1.4.2 needs a way to pause or turn down audio that plays automatically for more than 3 seconds, and 2.2.2 needs a way to pause moving content that starts on its own, lasts longer than five seconds and sits alongside other content.

A custom player has to rebuild the same functions itself. Criterion 2.1.1 requires all functionality to be operable through a keyboard, and criterion 4.1.2 requires each control's name and role to be programmatically determinable, so custom play, seek and volume controls need keyboard support and accessible names.

Frequently asked questions

How do I show play and pause buttons on an HTML video?
Add the controls attribute to the video element. The browser then draws its own play, pause, seek and volume controls without any JavaScript.
How do I hide the controls on an HTML video?
Remove the controls attribute, or set the video's controls property to false in JavaScript. Browsers may still offer playback options in a context menu.
How do I hide the download button in the video controls?
Add the controlslist attribute with the value nodownload next to the controls attribute. MDN's compatibility data lists controlslist as unsupported in Firefox and Safari.
Why does my audio element not show up on the page?
An audio element without the controls attribute is not rendered. Add controls, or build your own player with buttons that call play() and pause().
Should I use the controls attribute or build a custom video player?
Start with the controls attribute unless you need the same look in every browser. MDN notes that the native controls differ between browsers and that a consistent look takes custom controls. A custom player has to rebuild caption switching and fullscreen, which the HTML Standard expects native controls to include, and WCAG 2.1.1 requires its controls to work from a keyboard.
Does setting controls to false in HTML hide the controls?
No, the controls attribute shows the controls whatever value it has. It is a boolean attribute, so hiding the controls means removing it.