Latest web development tutorials

HTML <label> tag

Examples

With two input fields and related marks simple HTML form:

<form action="demo_form.asp">
<label for="male">Male</label>
<input type="radio" name="sex" id="male" value="male"><br>
<label for="female">Female</label>
<input type="radio" name="sex" id="female" value="female"><br>
<input type="submit" value="提交">
</form>

try it"

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Most browsers support <label> tag.


Tag definitions and instructions

<Label> tag for the input element defines the label (tag).

label elements do not exhibit any special effects to the user. However, it is for the mouse users to improve usability. If you click on the text within the label element, it will trigger this control. That is, when the user selects the tab, the browser will automatically focus to the associated form controls and labels.

<Label> tag attributes should be the same for the id attribute related elements.


Tips and Notes

Tip: "for" property of the label bound to another element.Please set the value "for" property to the value of the id attribute of the related elements.


Differences between HTML 4.01 and HTML5

"Form" attribute of HTML5 is the new property.


Attributes

New: HTML5 new property.

属性 描述
for element_id 规定 label 与哪个表单元素绑定。
form New form_id 规定 label 字段所属的一个或多个表单。


Global Properties

<label> tag supports the global attributes, view complete the property sheet HTML Global Attributes .


Event Properties

<label> tag supports all HTML event attributes .