Name

label — HTML 4.01 | HTML5

Synopsis

<label> . . . </label>

Used to attach information to controls. Each label element is associated with exactly one form control. The label element may contain the form control, or it may use the for attribute to identify the control by its id value.

Notes

In HTML5, a label may contain the input and use the for/id method.

Start/End Tags

Required/Required

Attributes

Core, Internationalization, Events, Focus, HTML5 Global Attributes

for="text"

Explicitly associates the label with the control by matching the value of the for attribute with the value of the id attribute within the control element.

form="id of the form owner"

Explicitly associates the label element with its associated form (its form owner). With this method, the label does not need to be the child of the applicable form element.

Examples

Form control and its labeling text contained within the label element:

<label>Last Name: <input type="text" size="32"></label>

Using the for/id method to associate the form control with its labeling text:

<label for="lastname">Last Name:</label>
<input type="text" id="lastname" size="32">

Get HTML & XHTML Pocket Reference, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.