HTML is getting cool again: Meet the Invoker Commands API
For years, frontend development has had a slightly embarrassing relationship with HTML. We all read about semantic HTML, we talk about using the right landmarks, the right attributes, accessible forms, and meaningful elements. And then we go back to writing React. While the whole industry is obsessed with AI, browsers are shipping features that make the platform even more capable. Features that…
Frontend development has traditionally had a strained relationship with HTML, despite the emphasis on semantic markup, proper landmarks, accessible forms, and meaningful elements. Despite the industry's focus on AI, browsers have introduced features that enhance platform capabilities, including HTML-based UI behavior. However, these advances are often overlooked or undervalued through outdated practices. For instance, opening a dialog or popover historically required significant custom boilerplate code.
A button would be created with an ID, a dialog element would be defined with its ID, and then JavaScript would be used to open and close the dialog upon button clicks. This process, while understandable, is repetitive and can be simplified using the Invoker Commands API. This API enables us to declaratively assign behaviors to buttons, allowing us to control interactive elements directly in HTML. The key attributes are commandFor and command.
The commandFor attribute transforms a button into a command invoker, specifying the ID of the element to control. The command attribute defines the action to be performed on that element. For example, a button can be configured to "toggle-popover" by setting commandFor to the ID of the popover element and command to "toggle-popover". Similarly, a "close-popover" action can be defined by setting commandFor back to the popover ID and command to "close-popover".
This approach can be applied in any framework, such as React, where the JSX property commandFor is used instead of commandFor, while the resulting HTML attribute remains the same. The shift in responsibility from developers to the browser is significant. While the reduction in lines of JavaScript may seem small, it represents a notable move towards less reliance on JavaScript.
However, it is essential to note that the Invoker Commands API is relatively new, with baseline support in 2025 and cross-browser availability in the latest versions since December 2025. Older browsers might not support it.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.