HTML commandfor Attribute
The commandfor attribute names, by id, the element that a button controls with its command attribute, such as a dialog or popover.
Description
The commandfor attribute of the <button> element holds the id of the element that the button controls when it is activated, using the action named in its command 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
- idThe id of the element to control, in the same document (or shadow root) as the button.
Applies To
Example
Browser Support
The following information will show you the current browser support for the HTML commandfor attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.
Desktop





Tablets & Mobile





