HTML

HTML Label: Syntax, Usage, and Examples

The HTML label element connects form input fields with readable text that explains their purpose. By using the label HTML tag, you give users and assistive technologies a better understanding of what data to enter into a field. It improves accessibility, enhances usability, and helps create cleaner, more semantic forms.

How to Use a Label in HTML

The most common way to write a label in HTML is by pairing the <label> element with a form control like an <input>, <textarea>, or <select>. The connection happens through the for attribute, which matches the id of the associated form field.

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

In this example, the label is visually linked to the input field. When users click the label text, the browser focuses the input box, improving form navigation and accessibility.

You can also nest the input element inside the label instead of using the for attribute:

<label>
  Email Address
  <input type="email" name="email">
</label>

This method creates the same behavior but doesn’t require using IDs.

When to Use HTML Label

Use the HTML label element every time you create a form field that requires user input. Labels clarify what users are expected to do, and they’re especially helpful for screen readers and other assistive tools.

Creating Accessible Forms

Screen readers rely on labels to describe form fields. Without them, users who navigate using keyboards or assistive technology won’t know what information to enter.

<label for="username">Username</label>
<input type="text" id="username" name="username">

Using label HTML elements makes your site more inclusive by providing clear context.

Grouping Radio Buttons or Checkboxes

Use labels with for attributes or wrap them around each input to clearly explain choices.

<input type="radio" id="option1" name="choice" value="1">
<label for="option1">Option 1</label>

<input type="radio" id="option2" name="choice" value="2">
<label for="option2">Option 2</label>

Users can click on the text “Option 1” or “Option 2” to select the corresponding radio button, which increases ease of use.

Enhancing Mobile Usability

On mobile devices, having a clickable label makes it easier for users to tap small form fields. Wrapping inputs with the HTML label element expands the clickable area.

<label>
  <input type="checkbox" name="subscribe">
  Subscribe to newsletter
</label>

This increases form accessibility without relying on precise touch input.

Examples of Label HTML in Action

Standard Input Field with Label

<label for="firstName">First Name</label>
<input type="text" id="firstName" name="firstName">

The label clearly indicates the purpose of the input field.

Wrapping a Label Around a Checkbox

<label>
  <input type="checkbox" name="accept">
  I agree to the terms and conditions
</label>

This format improves usability on both desktop and mobile.

Label with a Textarea

<label for="message">Your Message</label>
<textarea id="message" name="message" rows="5"></textarea>

Even non-input elements like <textarea> benefit from proper labeling.

Label for Select Dropdown

<label for="country">Select your country</label>
<select id="country" name="country">
  <option value="us">United States</option>
  <option value="ca">Canada</option>
</select>

This example uses label HTML to describe the purpose of a dropdown menu.

Learn More About Label in HTML

Why Use the Label Element?

The label HTML element offers several advantages:

  • Improved accessibility: Screen readers associate the label text with the input field.
  • Clickable area expansion: Clicking the label focuses the input.
  • Better user experience: Users understand what data belongs in each field.
  • Cleaner HTML structure: Helps separate logic, styling, and content in forms.

Without labels, your forms become harder to navigate and may not meet accessibility standards.

How to Use a Label in HTML with JavaScript

When working with dynamic forms, JavaScript can manipulate labels just like any other HTML element.

<label for="search">Search</label>
<input type="text" id="search">
<script>
  document.querySelector("label[for='search']").textContent = "Search by keyword";
</script>

This flexibility is helpful for real-time changes, error messages, or translations.

Customizing Label Style with CSS

You can style the HTML label element just like any text element. Here's a simple example:

<style>
  label {
    display: block;
    font-weight: bold;
    margin-bottom: 6px;
  }
</style>

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

This styling makes the label more prominent and readable, especially in longer forms.

Labels for Grouped Fields

Sometimes, you want to associate a single label with a group of inputs (like phone number fields or date pickers). In these cases, use a <fieldset> and <legend> for broader labeling:

<fieldset>
  <legend>Date of Birth</legend>
  <input type="number" name="day" placeholder="DD">
  <input type="number" name="month" placeholder="MM">
  <input type="number" name="year" placeholder="YYYY">
</fieldset>

While not a <label> itself, <legend> works similarly and improves form clarity.

Placeholder vs Label

People often confuse the placeholder attribute with the HTML label element. Here's how they differ:

  • Placeholder is text inside the input that disappears when you type.
  • Label is external and always visible.

Example:

<label for="username">Username</label>
<input type="text" id="username" placeholder="Enter your username">

Placeholders should never replace labels. They’re best used for hints or formatting guidance.

Accessibility Best Practices

To maximize accessibility when using the label in HTML:

  • Always associate labels with form fields using for and id or wrap the input directly.
  • Don’t use placeholder text as a substitute.
  • Avoid placing labels after input fields—screen readers may not interpret them correctly.
  • If a field is required, indicate this clearly in the label or with ARIA attributes.

Example of a required field:

<label for="email">Email <span aria-hidden="true">*</span></label>
<input type="email" id="email" required aria-required="true">

Labeling Hidden or Screen Reader-Only Fields

In some cases, you may want to hide a label visually but keep it accessible to screen readers:

<style>
  .sr-only {
    position: absolute;
    left: -9999px;
  }
</style>

<label for="promoCode" class="sr-only">Promo Code</label>
<input type="text" id="promoCode" name="promoCode">

This technique balances visual design with accessibility compliance.

Using the HTML label element is essential for building accessible, user-friendly forms. It allows you to associate readable descriptions with interactive fields, helping both users and assistive technology understand what each form field is for. Whether you're working on a simple email signup form or a full checkout process, applying label HTML correctly ensures clarity, improves usability, and keeps your forms compliant with modern standards.

Now that you know how to use a label in HTML, you can confidently create forms that are not just functional—but also accessible, semantic, and easy to use across devices.

Learn HTML for Free
Start learning now
button icon
To advance beyond this tutorial and learn HTML by doing, try the interactive experience of Mimo. Whether you're starting from scratch or brushing up your coding skills, Mimo helps you take your coding journey above and beyond.

Sign up or download Mimo from the App Store or Google Play to enhance your programming skills and prepare for a career in tech.

You can code, too.

© 2025 Mimo GmbH