label

<label>

HTML <label>元素表示用户界面中项目的标题。

内容类别 Flow content, phrasing content, interactive content, form-associated element, palpable content.
允许的内容 Phrasing content ,但没有子代标签元素。除了有标签的控制以外,不允许有任何可标记的元素。
标记遗漏没有,起始和结束标签都是强制性的。
允许父级任何接受短语内容的元素。
允许ARIA角色没有
DOM界面HTMLLabelElement

属性

这个元素包含全局属性。

for

 label元素可同时有属性和包含控件元素(contained control element),只要此for属性指向包含控件元素。

form

此内容属性已于2016年4月28日从HTML规范中删除。但是,脚本仍然可以访问只读HTMLLabelElement.form属性; 它将返回标签的关联控件所属的表单,或者null标签与控件没有关联,或者控件不是表单的一部分。

使用说明

  • <label>通过将控件元素放置在<label>元素中,或者通过使用for属性,可以将A 与控件相关联。这种控制被称为标签元素的标签控制。一个输入可以与多个标签相关联。

  • 标签本身并不直接与表单关联。他们只是通过与他们相关的控制与形式间接联系在一起。

例子

简单的标签示例

<label>Click me <input type="text"></label>

使用“for”属性

<label for="username">Click me</label> <input type="text" id="username">

规范

SpecificationStatusComment
HTML Living StandardThe definition of '<label>' in that specification.Living Standard
HTML5The definition of '<label>' in that specification.Recommendation
HTML 4.01 SpecificationThe definition of '<label>' in that specification.RecommendationInitial definition

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)
for(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)
form(Yes)(Yes)(Yes) — 49(Yes)(Yes)(Yes)

FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)
for(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)
form(Yes)(Yes)(Yes)(Yes) — 49(Yes)(Yes)(Yes)