label elementlabel elements.formforinterface HTMLLabelElement : HTMLElement {
readonly attribute HTMLFormElement? form;
attribute DOMString htmlFor;
readonly attribute HTMLElement? control;
};
The label represents a caption in a
user interface. The caption can be associated with a specific form
control, either using for attribute, or by putting the form
control inside the label element itself.
The for attribute
may be specified to indicate a form control with which the caption
is to be associated. If the attribute is specified, the attribute's
value must be the ID of a labelable element in the same
Document as the label element.
The form attribute is used to
explicitly associate the label element with its
form owner.
The following example shows three form controls each with a label, two of which have small text showing the right format for users to use.
<p><label>Full name: <input name=fn> <small>Format: First Last</small></label></p> <p><label>Age: <input name=age type=number min=0></label></p> <p><label>Post code: <input name=pc> <small>Format: AB12 3CD</small></label></p>
controlReturns the form control that is associated with this element.
The htmlFor IDL
attribute must reflect the for content attribute.