HTML/Elements/label

From Web Education Community Group
< HTML‎ | Elements
Jump to: navigation, search

<label>

The <label> element represents a caption in a user interface.

Point

  • The caption can be associated with a specific form control:


HTML Attributes

  • form = string
    Associate the fieldset element with its form owner.


  • for = string
    Specified to indicate a form control with which the caption is to be associated.
    The attribute's value must be the ID of a labelable form-associated element in the same Document as the label element.


See also global attributes.


Examples

Example A

Using for attribute [try it]:

<input type="checkbox" id="lost" name="lost"> <label for="lost">Lost</label>

Label01.png

Example B

By putting the form control inside the label element itself [try it]:

<label><input type="checkbox" name="lost"> Lost</label>

Label01.png

HTML Reference

The HTML5 specification defines the <label> element in 4.10.6 The label element.