HTMLElement: command event

Baseline 2025
Newly available

Since December 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

The command event of the HTMLElement interface fires on an element that is controlled via a button with valid commandForElement and command values, whenever the button is interacted with (e.g., it is clicked).

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js
addEventListener("command", (event) => { })

oncommand = (event) => { }

Event type

A CommandEvent. Inherits from Event.

Event CommandEvent

Examples

Basic example

js
const popover = document.getElementById("mypopover");

// …

popover.addEventListener("command", (event) => {
  if (event.command === "show-popover") {
    console.log("Popover is about to be shown");
  }
});

Event dispatch and cancellation

It is worth pointing out that command events fire on the element being invoked. If the button is clicked, it will first dispatch a click event which, if cancelled, then the command event will not fire and the default behavior will not be run. In addition to cancelling the click event on the button, it is also possible to cancel the command event.

For example:

js
button.addEventListener("click", (event) => {
  event.preventDefault(); // the `command` event will never fire
});
js
element.addEventListener("command", (event) => {
  event.preventDefault(); // the `command` event fires but the default behavior is cancelled
});

Specifications

Specification
HTML
# event-command

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
command event
Chrome – Full support
Chrome 135 (Release date: 2025-04-01)
footnote Full support
Edge – Full support
Edge 135 (Release date: 2025-04-04)
footnote Full support
Firefox – Full support
Firefox 144 (Release date: 2025-10-14)
footnote Full support
Opera – Full support
Opera 120 (Release date: 2025-07-02)
footnote Full support
Safari – Full support
Safari 26.2 (Release date: 2025-12-12)
footnote Full support
Chrome Android – Full support
Chrome Android 135 (Release date: 2025-04-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 144 (Release date: 2025-10-14)
footnote Full support
Opera Android – Full support
Opera Android 89 (Release date: 2025-04-29)
footnote Full support
Safari on iOS – Full support
Safari on iOS 26.2 (Release date: 2025-12-12)
footnote Full support
Samsung Internet – Full support
Samsung Internet 29 (Release date: 2025-10-25)
footnote Full support
WebView Android – Full support
WebView Android 135 (Release date: 2025-04-01)
footnote Full support
WebView on iOS – Full support
WebView on iOS 26.2 (Release date: 2025-12-12)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also