Favorites

HTML command Attribute

command
HTML AttributeThis attribute is supported by all modern browsers.
Updated 22nd November 2026

The command attribute sets the action a button performs on the element named in commandfor, such as show-modal, close or toggle-popover.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

Description

The command attribute of the <button> element specifies the action the button performs on the element referenced by its commandfor attribute.

Together, command and commandfor form invoker commands: a declarative way for a button to control another element without JavaScript event handlers. commandfor holds the id of the element to control, and command names the action to perform on it.

Built-in commands include show-modal, close and request-close for <dialog> elements, and show-popover, hide-popover and toggle-popover for popovers. Custom commands start with two dashes (for example --rotate) and fire a command event on the target, which a script can handle.

Syntax

<button commandfor="id" command="value">

Values

  • show-modalOpens a <dialog> as a modal.
  • closeCloses a <dialog>.
  • request-closeRequests that a <dialog> closes (fires a cancelable cancel event).
  • show-popover / hide-popover / toggle-popoverShows, hides or toggles a popover.
  • --customA custom command name starting with two dashes, delivered to the target in a command event.

Applies To

Example

<button commandfor="dlg" command="show-modal">Open dialog</button>
<dialog id="dlg">
<p>Opened without JavaScript.</p>
<button commandfor="dlg" command="close">Close</button>
</dialog>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML command attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

This attribute is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee