HTML Attributes
HTML command attribute
Specifies an action a button requests on a target named by commandfor. Built-in commands include dialog and popover actions; custom commands use a double-hyphen prefix. Support is feature-dependent. Applicable elements include: <button>. Check each element’s value rules. For dialog requests, choose show-modal, close or request-close according to the desired behavior. A popover target instead uses show-popover, hide-popover or toggle-popover. Use a native button and test the actual target behavior, not merely attribute recognition.
Formal Syntax & Structure
html syntaxhtml
command="show-modal"Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| command | built-in keyword or --custom command | Use an action appropriate to the command target. A custom command begins with -- and can dispatch a command event. |
Working Example
Example Snippethtml
<button type="button" commandfor="notice" command="show-modal">Open notice</button><dialog id="notice" aria-labelledby="notice-title"> <h2 id="notice-title">Notice</h2> <form method="dialog"> <button>Close</button> </form></dialog>Browser Compatibility
Minimum supported versions across modern rendering engines
Blink (modern)
Chrome
135
Yes
Gecko
Firefox
144
Yes
WebKit
Safari
26.2
Yes
Basic button command attribute; individual commands and target behavior may differ.
HTML Living Standard