HTML Label Element
Picture a form with three empty boxes and no words next to them. You would have no idea what to type where. Now imagine you could not see the screen, and a voice only said "edit text... edit text... edit text." That is what a form without labels sounds like to someone using a screen reader.
The <label> element is the name tag of a form field. It is small, and it is one of the most important elements in HTML forms. A correct label makes a form clearer for everyone, easier to tap on a phone, and usable with assistive technology. A missing label is the most common accessibility problem on the web, and also one of the easiest to fix.
What You Will Learnβ
- What a
<label>does, and why every field needs one - The two ways to connect a label to a field:
forandid, or wrapping - Why labels make fields easier to click and tap
- Why a placeholder is not a label
- How to hide a label visually without hiding it from assistive technology
- How to add hints, required markers, and error text
- Labels for checkboxes, radio buttons, and other controls
- Common mistakes
The Basicsβ
A label is text that describes one form control. It is connected to that control, so the two behave as a pair.
- HTML Code
- Browser Output
<label for="email">Email address</label>
<input type="email" id="email" name="email" />
The connection comes from two matching values:
| On the label | On the field | Meaning |
|---|---|---|
for="email" | id="email" | "This label belongs to the field whose id is email" |
ididentifies the field on the page, so a label (or CSS or JavaScript) can point at it.nameis the key under which the value is sent to the server.
They are often the same word, but they do different jobs. A label uses for and id, never name.
Two Ways to Connect a Labelβ
1. Explicit: for and idβ
The label and the field sit separately, and are linked by matching attributes.
<label for="city">City</label>
<input type="text" id="city" name="city" />
- Works even when the label and field are far apart in the layout.
- Is the most flexible and the most widely recommended method.
- Each
idon the page must be unique.
2. Implicit: Wrappingβ
The field is placed inside the label. No for or id is needed.
<label>
City
<input type="text" name="city" />
</label>
- Quick to write, and common for checkboxes and radio buttons.
- Slightly harder to style when the label text and field must sit in separate columns.
Using Bothβ
For the best support in all tools, you can combine them. This is harmless, and useful when you are not sure how a tool handles wrapping:
<label for="city">
City
<input type="text" id="city" name="city" />
</label>
Use explicit (for and id) for text fields, and either for checkboxes and radio buttons. If you pick one method and use it consistently, your forms stay easy to maintain.
What a Label Gives Youβ
1. A Bigger Click Targetβ
Clicking or tapping a label activates its field: it puts the cursor in a text box, toggles a checkbox, or selects a radio button. This is a big help on phones, where a tiny checkbox is hard to hit.
Try it. Click the words next to each box:
The first box responds to a click on its text because of the label. The second does not, because it has none.
2. An Accessible Nameβ
Assistive technology reads the label as the field's name. For the email field above, a screen reader says:
"Email address, edit text, required."
Without a label, it says only "edit text," and the user cannot tell what to enter.
3. Voice Controlβ
People who control their computer by voice can say "click Email address" to reach the field. That works only if the field has a label with visible text that matches.
4. Better Searching and Testingβ
Tools that test or automate forms often find fields by their label text, so labeled forms are easier to maintain.
Every form control needs a programmatic label or name (WCAG success criterion "Labels or Instructions" and "Name, Role, Value"). It is one of the clearest rules in accessibility, and a missing label is the easiest failure to prevent.
A Placeholder Is Not a Labelβ
The placeholder attribute shows faint text inside an empty field. It looks like a label, which makes it a tempting shortcut. Do not use it as one.
- Placeholder only
- Label plus placeholder
<input type="email" name="email" placeholder="Email address" />
<label for="email">Email address</label>
<input
type="email"
id="email"
name="email"
placeholder="name@example.com"
/>
| Problem with placeholder-only fields | Why it matters |
|---|---|
| It disappears when the user starts typing | They forget what the field was for, especially in long forms |
| Low contrast by default | Hard to read for many people |
| Not always announced as the field's name | Support in assistive technology is inconsistent |
| Looks "already filled in" | Some users think the field is done and skip it |
| Cannot be clicked to focus the field | No bigger target |
| Often cut off in other languages | Translated text can be longer |
The right use for a placeholder is a short example of the format, such as name@example.com. Never use it for the field's name or for instructions that people need to keep seeing.
"Floating Labels"β
A popular design shows the label inside the field and moves it above as the user types. Done well, it is fine, because the label stays in the HTML and remains visible. Done badly, it is a placeholder in disguise. If you use floating labels, test them with a screen reader and at high zoom.
Hiding a Label (Carefully)β
Sometimes a design shows a field with no visible label, such as a search box next to a magnifier button. The field still needs a label for assistive technology. There are three acceptable ways.
Option 1: A Visually Hidden Label (best)β
Keep a real <label>, and hide it from the eye only, using a CSS class:
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
border: 0;
}
- HTML Code
- Browser Output
<form action="/search" method="get" role="search">
<label for="q" class="visually-hidden">Search the site</label>
<input type="search" id="q" name="q" placeholder="Search..." />
<button type="submit">Go</button>
</form>
The label is invisible on screen, but a screen reader announces "Search the site, search edit text." Sighted users get a visual clue from the button and the placeholder.
Option 2: aria-labelβ
Put the name straight on the field:
<input type="search" name="q" aria-label="Search the site" />
Simple, but it has no visible text, so voice control users and people who translate the page may miss it.
Option 3: aria-labelledbyβ
Point the field at text that already exists on the page:
<h2 id="search-title">Search</h2>
<input type="search" name="q" aria-labelledby="search-title" />
Do not hide a label with display: none or visibility: hidden, or the hidden attribute. That removes it from assistive technology too, and the field is nameless again. Use the visually hidden technique above.
Labels for Checkboxes and Radio Buttonsβ
For these controls, the label sits beside the box, and is usually written by wrapping.
- HTML Code
- Browser Output
<label>
<input type="checkbox" name="news" />
Send me weekly tips
</label>
<p>Your level:</p>
<label>
<input type="radio" name="level" value="beginner" />
Beginner
</label>
<label>
<input type="radio" name="level" value="advanced" />
Advanced
</label>
Each radio button has its own label ("Beginner," "Advanced"). The question "Your level:" belongs to the group, and the correct element for naming a group is <fieldset> with <legend>, which you will learn in Fieldset and Legend. A <label> names one control. A <legend> names a group.
Which Elements Can Have a Label?β
A label can be connected to any labelable element:
| Labelable | Example |
|---|---|
<input> (except type="hidden") | Text, email, checkbox, radio, file... |
<textarea> | A message box |
<select> | A drop-down |
<button> | Gets its name from its own text, but a label works too |
<meter> and <progress> | Gauges and progress bars |
<output> | A calculated result |
An <input type="hidden"> has no visible control, so it needs no label.
Hints, Required Markers, and Errorsβ
A label gives the name. Extra help belongs in separate text that is connected to the field.
- HTML Code
- Browser Output
<label for="pw">Password</label>
<input
type="password"
id="pw"
name="password"
autocomplete="new-password"
aria-describedby="pw-hint"
required
/>
<p id="pw-hint">At least 12 characters. A short sentence works well.</p>
aria-describedby points at the hint's id. A screen reader reads the label first ("Password"), then the field type, then the hint. The same trick connects error messages to fields, which you will see in Accessible Forms.
Marking Required Fieldsβ
If a field is required, say so in the label, and use the required attribute too.
<label for="name">Full name <span aria-hidden="true">*</span></label>
<input type="text" id="name" name="name" required />
Whatever symbol you pick, explain it near the top of the form ("* means required"), or write "(required)" in words. Do not use color alone.
| Approach | Notes |
|---|---|
| "Full name (required)" | The clearest, and the easiest to translate |
* with a note "* required" | Common, but explain it |
| Marking the optional fields instead, "(optional)" | Good when most fields are required |
| Red label color only | Not enough on its own |
Writing Good Label Textβ
- Be short and clear. "Email address," not "Please enter the email address that you use."
- Name the content, not the control. "Email," not "Text box 1."
- Be specific. "Delivery postcode" beats "Code."
- Put the label near the field, usually above it, or beside it for checkboxes. Above-field labels also fit narrow phone screens best.
- Use sentence case, and no ending colon is needed.
- Do not rely on position alone. Label text must make sense when heard by itself.
- Match the label to the field's purpose, so that
autocompleteand voice control work.
Do Not Put Interactive Content Inside a Labelβ
A label is itself clickable, so nesting other interactive elements inside it causes confusion.
- Risky
- Safer
<label for="terms">
I accept the <a href="/terms">terms and conditions</a>
</label>
<input type="checkbox" id="terms" name="terms" />
<input type="checkbox" id="terms" name="terms" />
<label for="terms">I accept the terms and conditions</label>
<a href="/terms">Read the terms</a>
In the risky version, clicking the link and clicking the label do different things in the same spot, and it is easy to tick the box by accident when trying to follow the link. Many sites do use links inside labels, so it is not forbidden, but a separate link is clearer and safer.
Styling Labelsβ
A label is a normal inline element. Common styles:
label {
display: block; /* put the label above the field */
font-weight: 600;
margin-bottom: 0.25rem;
}
.checkbox-label {
display: flex; /* box and text side by side */
align-items: center;
gap: 0.5rem;
cursor: pointer;
}
A pointer cursor on clickable labels is a small hint that the label is active.
Global Audience Notesβ
- Write labels in the page's language, and set the
langattribute. - Keep them short. Translations can run much longer, and long labels wrap badly in narrow layouts.
- Do not build sentences from separate pieces (for example, a label before a field and a unit after it that together form a sentence), because word order differs between languages.
- Avoid slang and idioms, since translation tools handle plain words best.
- Be careful with "name" fields. "Full name" or "Name" suits more cultures than "First name" and "Last name."
- Leave room. Labels in some languages may be much longer than in English.
Common Mistakes to Avoidβ
- No label at all. The most common and most serious mistake.
- A
forthat does not match anyid, so the label is connected to nothing. - Duplicate
idvalues on the page, so labels point to the wrong field. - Using the placeholder as the label.
- Using
nameinfor. It must match theid. - Hiding labels with
display: none. It removes them from screen readers. - One label for a whole group of radio buttons. Use
<fieldset>and<legend>. - Putting a long paragraph inside a label. Move extra help to
aria-describedbytext. - Using
<p>or<span>in place of<label>. It looks the same, but it is not connected. - Wrong order of text and fields that makes the label ambiguous (for example, a label between two fields).
Practice Timeβ
Try these in your editor:
- Build a form with name, email, and message fields, each with an explicit label using
forandid. - Click each label, and confirm the matching field gets focus.
- Rewrite one field with a wrapping label instead.
- Add a checkbox, and make its label clickable.
- Replace a placeholder-only field with a label plus a placeholder example.
- Create a search field with a visually hidden label.
- Add a hint under a password field, and connect it with
aria-describedby. - Mark one field as required with
requiredand the text "(required)" in the label. - Break a
foron purpose, then notice the click behavior stops. Fix it. - Bonus: open your browser's Accessibility panel, and check the "name" shown for each field.
Quick Recapβ
Click a question to check your answer.
1. What does the <label> element do?
It gives a form control its visible and accessible name. Clicking the label activates the control, and screen readers announce the label text for it.
2. How do you connect a label to a field?
Either with for on the label matching the id on the field, or by wrapping the field inside the <label>.
3. What is the difference between id and name on a field?
id identifies the field on the page, for labels, CSS, and scripts. name is the key under which the field's value is sent to the server.
4. Why is a placeholder not a replacement for a label?
It disappears when typing, has low contrast, may not be announced as the name, and cannot be clicked to focus the field. Use it only for a short format example.
5. How can you hide a label visually but keep it accessible?
Use a visually hidden CSS class, so the label stays in the page for assistive technology. Do not use display: none. aria-label is a simpler alternative with some trade-offs.
6. How do you connect a hint to a field?
Give the hint an id, and add aria-describedby="that-id" to the field. Screen readers then read the hint after the label.
Key Takeawaysβ
- Every form control needs a label. A missing one is the most common form accessibility failure.
- Connect a label with
forand a matchingid, or by wrapping the control. Never usenameinfor. - Labels enlarge the click and tap target, give fields an accessible name, and support voice control.
- A placeholder is not a label. Use it only for a format example.
- If a design hides a label, hide it visually with CSS, never with
display: none. - Put hints and errors in separate text linked with
aria-describedby, and mark required fields in words, not by color alone. - Write short, plain labels that translate well.
Now your fields have names. Next, learn the element that does the real work: the field itself, in Input Element, or return to the Forms overview.