<legend>:字段集标题元素

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

<legend> HTML 元素表示其父元素 <fieldset> 内容的标题。

尝试一下

<fieldset>
  <legend>Choose your favorite monster</legend>

  <input type="radio" id="kraken" name="monster" value="K" />
  <label for="kraken">Kraken</label><br />

  <input type="radio" id="sasquatch" name="monster" value="S" />
  <label for="sasquatch">Sasquatch</label><br />

  <input type="radio" id="mothman" name="monster" value="M" />
  <label for="mothman">Mothman</label>
</fieldset>
legend {
  background-color: #000;
  color: #fff;
  padding: 3px 6px;
}

input {
  margin: 0.4rem;
}

属性

这个元素只包含全局属性

示例

有关 <legend> 的示例,请参阅 <form>

技术概要

内容分类 无。
允许的内容 短语内容标题(h1–h6 元素)。
标签省略 不允许,开始标签和结束标签都不能省略。
允许的父元素 一个 <fieldset>,其第一个子元素是此 <legend> 元素
隐含的 ARIA 角色 没有对应的角色
允许的 ARIA 角色 没有允许的 role
DOM 接口 HTMLLegendElement

规范

Specification
HTML
# the-legend-element

浏览器兼容性

参见