Live Preview
A simple labeled contact form:

By the end of this tutorial, you’ll write accessible, user-friendly form labels that work for everyone.
Link labels to controls with for and matching id.
Wrap inputs inside <label> when layout allows.
Label radios, checkboxes, and dropdown menus correctly.
Know why placeholders cannot replace visible labels.
Style labels for clear, consistent form layouts.
Help screen readers and keyboard users interact with forms.
<label> Tag?The label element (<label>) represents a caption for a labelable form control — such as input, select, textarea, button, meter, output, or progress. A proper label tells users what data to enter and gives assistive technology an accessible name for the field.
When a label is correctly associated, clicking the label text focuses or activates the control. This enlarges the clickable target and is especially helpful on touch screens and for users with motor difficulties.
Labels are one of the most important accessibility features in HTML forms. Every visible field should have a descriptive label — do not rely on placeholder text alone.
The most common pattern uses for on the label and a matching id on the control:
<label for="username">Username:</label>
<input type="text" id="username" name="username">You can also nest the control inside the label — no for attribute needed:
<label>
Email:
<input type="email" name="email">
</label>for must exactly match the associated control’s id.id must be unique on the page.id.for/id when label and input are in different layout containers.| Use Case | Code Snippet | Notes |
|---|---|---|
| Text input | <label for="name">Name</label> | Match id="name" on input |
| Checkbox | <label for="agree">I agree</label> | Clicking label toggles checkbox |
| Select menu | <label for="country">Country</label> | Pairs with <select id="country"> |
| Textarea | <label for="msg">Message</label> | Works with multiline fields |
| Outside form | form="myForm" on label + control | Links control to distant form |
| Implicit wrap | <label>Text <input></label> | No for needed when nested |
<label> vs placeholderPlaceholders are hints inside the field; labels are persistent, accessible names:
| Feature | <label> | placeholder |
|---|---|---|
| Visibility | Always visible beside or above the field | Disappears when user types |
| Accessibility | Primary accessible name for the control | Not a label replacement |
| Click target | Clicking label focuses the field | No click behavior |
| Best practice | Required for every visible field | Optional hint text only |
The <label> element supports these specific attributes plus global attributes such as class:
for Explicit linkMatches the id of the associated labelable form control.
for="email"form AssociationAssociates the label with a form by id when the label sits outside the form element.
form="userForm"class GlobalCSS hook for layout, typography, and required-field indicators.
class="field-label"id GlobalUnique identifier when referencing the label from aria-labelledby.
id="email-label"<form id="userForm">
<label for="email" form="userForm">Email:</label>
<input type="email" id="email" name="email" form="userForm">
</form>Email fields, passwords, checkboxes, and dropdown menus with copy-ready label markup and live previews.
A simple labeled contact form:
Associate a label and input with a form using matching form and for/id values.
<form id="userForm">
<label for="email" form="userForm">Email:</label>
<input type="email" id="email" name="email" form="userForm">
</form>Use <label> on every form field — text inputs, passwords, checkboxes, radio buttons, selects, and textareas. Clear labels reduce errors and are required for accessible forms.
Label password inputs so users and assistive technology know what to enter.
<label for="password">Password:</label>
<input type="password" id="password" name="password">Place the label after the checkbox so clicking the text toggles the box.
<input type="checkbox" id="subscribe" name="subscribe">
<label for="subscribe">Subscribe to newsletter</label>Help users understand what a dropdown menu is for.
<label for="country">Select your country:</label>
<select id="country" name="country">
<option value="usa">USA</option>
<option value="canada">Canada</option>
</select>Style labels for readable, consistent form layouts. Keep labels visible and maintain strong contrast:
font-weight Medium-weight labelsdisplay: block Stacked label + input.required Required field markercursor Pointer on clickable labels/* Form label styling */
label {
display: block;
font-weight: 500;
color: #0f172a;
margin-bottom: 0.35rem;
cursor: pointer;
}
label.required::after {
content: " *";
color: #dc2626;
}
.demo-form__choice label {
display: inline;
font-weight: 400;
margin: 0;
}Live styled labels
Labels are essential for inclusive forms:
<label> element.Connect them with for/id or nest the input inside the label.
Clicking label text focuses or activates the associated field.
Screen readers announce the label as the field’s accessible name.
Users understand each field and can interact with forms more easily.
The <label> element is fully supported in all browsers, including legacy Internet Explorer.
From legacy Internet Explorer to the latest mobile browsers — the label element is fully supported for accessible forms.
Bottom line: Ship accessible forms with confidence. The <label> element is safe to use in every production environment today.
The <label> tag is a small element with a big impact on form usability and accessibility. Whether you are building login pages, contact forms, or settings panels, clear labels help every user understand what to enter.
Remember to pair every control with a label, use for and id correctly, and never rely on placeholder text alone.
for and matching id on every fieldid on multiple controls<label>Bookmark these before you ship — they’ll keep your forms accessible and easy to use.
<label> names a form control for users and assistive tech.
Match for on label to id on the control.
Clicking the label focuses or toggles the field.
UXAlways label radios, checkboxes, and selects.
FormsLabels stay visible; placeholders are hints only.
AccessibilityWorks in every browser, including legacy IE.
Compatibilityid matches the for value.<label> is implicit labeling and works without a for attribute.input (except hidden), select, textarea, button, meter, output, and progress.Try email, password, checkbox, and select labels in the interactive editor.
6 people found this page helpful