HTML <label> Tag
The <label> tag in HTML is used to provide a usability improvement for mouse users i.e, if a user clicks on the text within the <label> element, it toggles the control. The <label> tag defines the label for <button>, <input>, <meter>, <output>, <progress>, <select>, or <textarea> element.
The <label> tag can be used in two ways:
- Firstly, use <label> tag by providing the <input> and id attribute. The <label> tag needs a for attribute whose value is the same as input id.
- Alternatively, <input> tag use directly inside the <label> tag. In this case, the for and id attributes are not needed because the association is implicit.
<label> form content... </label>
- for: It refers to the input control that this label is for. Its value must be the same as the value of the input control’s “id” attribute.
- form: It refers to the form to which the label belongs to.
Example 1: Here we will use the input tag outside the label tag.
Example 2: Here we will use the input tag inside the level tag.
- Google Chrome
- Edge 12
- Internet Explorer