Posts in current category

HTML5 <label> tag

May 03, 2021 16:00 HTML5

Table of contents

HTML5 is used to tag input elements.

A simple HTML form with two input fields and related tags:

<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="提交">
Try it out . . .

Browser support

HTML5 <label> tag HTML5 <label> tag HTML5 <label> tag HTML5 <label> tag HTML5 <label> tag

Most browsers currently support the hashtag.

Label definition and instructions for use

The label defines labels (tags) for input elements.

Label elements do not render any special effects to the user. H owever, it improves availability for mouse users. T his control is triggered if you click on the text within the label element. That is, when the user selects the label, the browser automatically turns the focus to the label-related form control.

The for property of the label should be the same as the id property of the related element.

Tips and comments

Tip: The "for" property binds the label to another element. Set the value of the "for" property to the value of the id property of the related element.

The difference between HTML 4.01 and HTML5

The "form" property is a new property of HTML5.


New: HTML5 new property.

Property Value Describe
for element_id Specifies which form element the label is bound to.
form New form_id Specifies one or more forms to which the label field belongs.

Global properties

The label supports global properties and views the full property sheet HTML global properties.

The event property

The label supports all HTML event properties.