coderef

Invoker commandsBaseline · Newly available

The command and commandfor attributes for the <button> HTML element dispatch an action to an element when the button is invoked (by click or keystroke), as a declarative alternative to addEventListener() calls or onclick attribute handlers.

Works in the latest version of every major browser, but older devices may not support it yet. Baseline since Dec 12, 2025.

Browser support

DesktopChrome
1–134Not supported
135+Supportedsince Apr 1, 2025
Current: 155
Edge
12–134Not supported
135+Supportedsince Apr 4, 2025
Current: 154
Firefox
1–143Not supported
144+Supportedsince Oct 14, 2025
Current: 157
Safari
1–26.1Not supported
26.2+Supportedsince Dec 12, 2025
Current: 27
MobileChrome Android
18–134Not supported
135+Supportedsince Apr 1, 2025
Current: 155
Firefox Android
4–143Not supported
144+Supportedsince Oct 14, 2025
Current: 157
Safari iOS
1–26.1Not supported
26.2+Supportedsince Dec 12, 2025
Current: 27

How to use

Every current browser supports this, but it only became Baseline on Dec 12, 2025. Use it as a progressive enhancement, or keep a fallback if you support older devices.

Example

Full syntax and examples are on MDN: CommandEvent.

Feature detection

JS · check before using
if ("CommandEvent" in globalThis) {
  // CommandEvent is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

Support for each part of the feature (9). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
CommandEvent13513514426.213514426.2
CommandEvent.CommandEvent13513514426.213514426.2
CommandEvent.command13513514426.213514426.2
CommandEvent.source13513514426.213514426.2
HTMLButtonElement.command13513514426.213514426.2
HTMLButtonElement.commandForElement13513514426.213514426.2
HTMLElement.command_event13513514426.213514426.2
button.command13513514426.213514426.2
button.commandfor13513514426.213514426.2