HTML command Attribute
The command attribute sets the action a button performs on the element named in commandfor, such as show-modal, close or toggle-popover.
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
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.
Desktop





Tablets & Mobile





