Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

<label>

A label for a form field.

Syntax

<label for="field-id">Label</label>

Attributes

ParameterTypeDescription
foridThe `id` of the field the label belongs to.

Examples

The label is linked to the field with for and id:

<label for="email">Email</label>
<input type="email" id="email">

Or the field right inside the label:

<label>
  <input type="checkbox"> Remember me
</label>

Notes

Clicking the label focuses the field or toggles the checkbox, and screen readers read the label together with the field. The for value must match the field's id exactly.

See also

  • <input> — An input field; its kind is set by the `type` attribute.
  • <form> — A form: collects data from its fields and sends it to the server.
  • id — A unique identifier of an element on the page.

Related recipes

In the tutorial

  • Labels and field groups — The label tag and linking a label to a field with for and id, nested labels, grouping fields with fieldset and legend.

Thanks for reading!

Donate to the site — we work hard for you.