WEB-28Optional
Wire buttons without click handlers
Connect buttons to popovers and dialogs in HTML with commandfor and command. Keep a fallback for older browsers.
How to do it
Use <button commandfor="menu" command="toggle-popover">, or command="show-modal" for a dialog. Chrome 135, Firefox 144 and Safari 26.2 support it. Where command is unsupported, add popovertarget="menu" from script. Build the dialog itself as Build modal dialogs with dialog says.
Examples
HTML example
<button commandfor="menu" command="toggle-popover">Menu</button>
<nav popover id="menu">…</nav>
<script>
if (!('command' in HTMLButtonElement.prototype))
for (const b of document.querySelectorAll('[command="toggle-popover"]'))
b.setAttribute('popovertarget', b.getAttribute('commandfor'));
</script>
How to check
In a browser that supports command, a test with JavaScript disabled clicks the button, and the popover or dialog opens.
Sources
Related rules
- WEB-26 Build modal dialogs with dialog in Website
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/website/interface/invoker-commands">Agent Wranglers website playbook</a>. In code you write, add a comment next to it with the same link.