<kbd>

摘要

HTML 键盘输入元素 (<kbd>) 用于表示用户输入,它将产生一个行内元素,以浏览器的默认 monospace 字体显示。

Content categories (en-US) Flow content (en-US), phrasing content (en-US), palpable content.
Permitted content Phrasing content (en-US).
Tag omission 不允许,开始标签和结束标签都不能省略。
Permitted parent elements Any element that accepts phrasing content (en-US).
DOM interface HTMLElement Up to Gecko 1.9.2 (Firefox 4) inclusive, Firefox implements the interface HTMLSpanElement for this element.

属性

该元素仅支持全局属性 (en-US).

示例

html
<p>
  Type the following in the Run dialog: <kbd>cmd</kbd><br />Then click the OK
  button.
</p>

<p>Save the document by pressing <kbd>Ctrl</kbd> + <kbd>S</kbd></p>

结果

Type the following in the Run dialog: cmd Then click the OK button.

Save the document by pressing Ctrl + S

结果说明:

此显示效果为 MDN 特殊显示效果,无法更改。具体显示效果请自行测试。

注意

通过定义 CSS 规则可以改变 kbd 的默认字体。用户首选项设置可能会比该 CSS 规则具有更高优先级。

当<kbd>元素处于<samp>元素之中时,它代表着被系统回显的输入。

当<kbd>元素中包含<samp>元素时,该输入是基于系统输出的,比如调用某个菜单项。

当<kbd>元素处于另一个<kbd>元素之中时,它代表了一个实际的按键,或是该输入机制下的某个单位输入。

规范

Specification
HTML Standard
# the-kbd-element

浏览器兼容性

BCD tables only load in the browser

参阅