Get to know MDN better
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 property of the HTMLButtonElement interface gets and sets the action to be performed on an element being controlled by this button. For this to have an effect, commandfor must be set.
It reflects the command HTML attribute.
A string. See the command attribute for valid values.
In this example, three buttons have been created using custom values for command. Each button targets the same image using the commandfor attribute.
An event listener is attached to the image using the command event. When one of the buttons is clicked, the listener runs code based on the custom command value assigned to the button, rotating the image and also updating it's alt text to indicate the new angle of the image.
| HTML # dom-button-command |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Oct 17, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.