
If you’ve ever found yourself entangled in JavaScript event listeners, context-aware handlers, and a sprinkle of spaghetti code, this one’s for you.
Say hello to the new HTML command and commandfor attributes — fresh out of the Chrome dev oven. These declarative gems let you wire up UI behavior in a way that’s simple, portable, and surprisingly powerful.
📰 Read the full Chrome announcement here
At their core, these attributes are about decoupling your UI markup from the logic that powers it.
⚠️ These attributes are only available on <button> elements (as of Chrome 124). They’re not valid on <a>, <div>, or other elements. This is part of the Invoker Commands API, which is currently limited to buttons.
No need for addEventListener on each button or wiring up logic separately — just pure HTML and a single listener on the target element.
The command and commandfor attributes offer a semantic, declarative way to attach UI actions to elements — and it plays nicely with any stack that outputs HTML, including:
Because you’re working with standard HTML and events, it’s framework-agnostic. You don’t need a JavaScript bundler or complex frontend setup to get started.
Let’s say you have an admin panel with multiple “Approve” buttons:
Here’s a basic example:
Now all your buttons just point to the right target with a commandfor, and the logic stays tidy on the receiving element. No data-* attributes. No bubbling mess.
Key Things to Know
The command and commandfor attributes feel like one of those “wait, why didn’t we always have this?” moments in HTML evolution. They reduce boilerplate, encourage clean markup, and play nicely with everything from handcrafted HTML to full-stack frameworks.
If you’re working in a platform that generates HTML — or just tired of wiring up every button manually — this is worth trying today (at least in Chrome). Future-you will thank you.
Bonus tip: These attributes are particularly handy for CMS plugins, admin panels, and static sites where you want structure without JS complexity.
Reference