Story Details

  • Introducing command And commandfor In HTML

    Posted: 2025-03-07 17:24:02

    The <command> and <commandfor> elements, now supported in Chrome 165, offer a declarative way to define commands and associate them with specific form controls. <command> represents a user action, like "copy" or "bold," and can be executed via various input methods (keyboard shortcuts, context menus, buttons). <commandfor> links a command to a specific HTML element, like a text input, clarifying which element the command operates on. This allows assistive technologies and other user agents to better understand the available actions and their targets, improving accessibility and user experience. This declarative approach simplifies command handling, especially for custom controls, and reduces reliance on JavaScript for basic command functionality.

    Summary of Comments ( 154 )
    https://news.ycombinator.com/item?id=43292056

    HN commenters generally expressed confusion about the purpose and utility of the new <command> and <commandfor> HTML elements. Several pointed out the seemingly niche use cases and questioned whether they solved a real problem developers faced, especially given existing keyboard shortcut solutions. Some compared them unfavorably to existing menu role attributes in ARIA and questioned their semantic value. Others expressed concern about discoverability and the potential for abuse in creating confusing or malicious interfaces. A few commenters attempted to find practical applications, like contextual menus for selected text or improved accessibility, but overall the reception was skeptical, with many suggesting the feature was overly complex for limited benefit.