HTML Attributes
HTML commandfor attribute
Identifies the target of a button command. Use an ID without a hash and an appropriate command value. Check browser support for declarative commands. Applicable elements include: <button>. Check each element’s value rules. The target must resolve by ID within the appropriate tree. Combine commandfor with a valid command for that target; neither attribute alone makes an arbitrary action happen. Use an ordinary button with a clear accessible name.
Formal Syntax & Structure
html syntaxhtml
commandfor="notice"Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| commandfor | element ID | Target element ID, without #; pair with command. |
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>