HTML Tags

HTML <label> Tag

The <label> tag is used to define a label for an HTML form control like <input>, <textarea>, or <select>.
Clicking the label automatically focuses the associated form control, improving usability and accessibility.

Associating labels with controls helps screen readers and improves user experience.

Syntax

<label for="inputId">Label Text</label>

Attributes

AttributeDescription
forAssociates the label with a form control’s id.
formSpecifies the form the label belongs to (useful if outside the form).
idAssigns a unique ID to the label element.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Label Example</title>
</head>
<body>
  <h2>Login Form</h2>
  <form action="/samples/form_processor.php" method="post">
    <label for="username">Username:</label>
    <input type="text" id="username" name="username" placeholder="Enter your username" required><br><br>

    <label for="password">Password:</label>
    <input type="password" id="password" name="password" placeholder="Enter your password" required><br><br>

    <input type="submit" value="Login">
  </form>
</body>
</html>

Output

Browser Output

You will see a form with labels next to text and password fields.
Clicking on the Username or Password label focuses the respective input field.
Use our TryIt Editor to test how labels improve usability.

Browser Support

Chrome
Chrome
Firefox
Firefox
Edge
Edge
Safari
Safari
Opera
Opera
IE
IE9+
✅Yes✅Yes✅Yes✅Yes✅Yes✅Yes

All major browser supports <lable> tag.

Notes

  • Always use <label> for better accessibility.
  • The for attribute must match the id of the input.
  • Can be used with all types of inputs, including <textarea> and <select>.
  • Reduces the chance of users clicking the wrong field.

Conclusion

The <label> tag is essential for accessible and user-friendly forms.
It ensures that users and assistive technologies can correctly associate form controls with their descriptions.

Sign In Form

User your email and password to singn in

Don’t have an account, signup here : 

HTML5 & CSS3

Tools and Tutorials

Want a Website

Want a website for your business ?

Please fill out the details below, so we can reach out to you.

Registration Form

Signup to track your record and much more.

We have sent you an email with a registration link. Please click the link to verify your email address, or enter the 6-digit OTP provided in the email.

Didn't receive the OTP. Regenerate OTP Resend