You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在HTML中显示特定快捷键?HTML5下替代<u>标签的规范方案

关于HTML5中标记accesskey快捷键字符的标准方案

Great question! You're right that the old <u> tag isn't recommended in HTML5 for this use case (since it's been repurposed for non-text annotations like spelling errors), and while a custom <span> with CSS works, there are more semantic and convenient options:

  • Use the <kbd> tag (most common & semantic choice):
    Originally designed to represent keyboard input, <kbd> is widely adopted in practice to highlight accesskey shortcuts. Browsers apply default styling (usually a subtle border or gray background) that makes the key stand out without needing custom CSS. Here's how you'd use it:

    <label accesskey="n"><kbd>n</kbd>ame</label>
    
  • Reconsider the <u> tag (with caution):
    HTML5 didn't fully remove <u>—it just redefined its semantic meaning (for things like misspelled words or Chinese proper noun markers). If you only care about the visual underline and don't mind stretching its intended use, you could still use it. But <kbd> is better because it carries the right "keyboard input" semantic that matches accesskey's purpose.

One quick note: Some browsers automatically underline accesskey characters based on user settings, but manually marking them ensures consistency across all environments.

内容的提问来源于stack exchange,提问作者Little Santi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:10:44