HTML Tutorial

HTML Tag: <label>

Usage of <label>

The <label> tag is used to provide a clickable caption for various form elements, such as input fields, checkboxes, and radio buttons. When the <label> tag is clicked, it triggers the associated form element, allowing users to input information or select options.

Attributes of <label>

  • for: Specifies the ID of the associated form element.
  • accesskey: Defines a keyboard shortcut to access the labeled element.

Examples with <label>

  • Input fields: <label for="username">Username:</label>
  • Checkboxes: <label for="agree">I agree to the terms and conditions</label>
  • Radio buttons: <label for="male">Male</label>

Exploring the <label> Tag

Here's a simple HTML example that demonstrates the usage of the <label> tag:

<form>
  <label for="name">Name:</label>
  <input type="text" id="name">
  <br>
  <label for="email">Email:</label>
  <input type="email" id="email">
  <br>
  <input type="submit" value="Submit">
</form>

In this example, the <label> tags provide user-friendly captions for the input fields. By clicking on the labels, users can easily input their name and email address into the corresponding fields.