<label>
HTML <label> Label
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <p>点击其中一个文本标签选中选项:</p> <form action="demo_form.phpp"> <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><br> <input type="submit" value="提交"> </form> </body> </html>
Running Example»
Click the "Run Instance" button to view the online instance
Browser support
Currently most browsers support < label> label.
Label definition and usage instructions
<label> The label defines the label (mark) for the input element. The
label element does not present any special effects to the user. However, it improves usability for mouse users. This control is triggered if you click on the text inside the label element. That is to say, when the user selects the label, the browser will automatically turn the focus to the form control related to the label.
<label> The for attribute of the label should be the same as the id attribute of the related element.
Tips and Notes
Tips:The "for" attribute can bind the label to another element. Please set the value of the "for" attribute to the value of the id attribute of the relevant element.
Differences between HTML 4.01 and HTML5
The "form" attribute is a new attribute of HTML5.
Attributes
New: HTML5 new attributes.
Attribute | Value | Description |
---|---|---|
for | element_id | Specifies which form element the label is bound to. |
formNew | form_id | Specifies one or more forms to which the label field belongs. |
Global attributes
<label> label supports global attributes, see the complete attribute table HTML global attributes.
Event attributes
<label> Label supports all HTML event attributes.