Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

label — a control caption

The `label` element gives a control a caption. Associate it using `for` and `id`, or place the control inside the label.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<label for="control-id">Caption</label>
<input id="control-id">

<label>Caption <input></label>

label represents a user-interface caption. Its for attribute targets a labelable element's id in the same tree, not its name. Without for, the first labelable descendant is targeted; an invalid for does not fall back to this mechanism.

Do not nest label elements or additional labelable controls. An input with type="hidden" is not labelable. One control can have multiple labels. Both label tags are required.

Clicking a label may activate its control, but behavior depends on the platform. The DOM property label.control returns the associated control or null.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Label association</title>
<label for="email">Email</label>
<input id="email" type="email">
<script>
  const label = document.querySelector('label');
  const input = document.querySelector('input');
  console.log(label.control === input);
</script>
</html>

Result

true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources