Categories
Web development

HTML label tag

HTML label tag

The HTML <label> tag specifies a label for following elements:

<input type=”checkbox”>

<input type=”color”>

<input type=”date”>

<input type=”datetime-local”>

<input type=”email”>

<input type=”file”>

<input type=”month”>

<input type=”number”>

<input type=”password”>

<input type=”radio”>

<input type=”range”>

<input type=”search”>

<input type=”tel”>

<input type=”text”>

<input type=”time”>

<input type=”url”>

<input type=”week”>

<meter>

<progress>

<select>

<textarea>

Example:

<!DOCTYPE html>
<html>
<body>
<div><h3>How many cats do you have?</h3>
  <input type="checkbox" id="one" name="one" value="one">
  <label for="one"> One</label><br>   
  <input type="checkbox" id="vehicle2" name="two" value="two">
  <label for="two"> Two</label><br>     
  <input type="checkbox" id="two" name="three" value="three">
  <label for="three"> Three</label><br>
  <input type="checkbox" id="other" name="other" value="other">
  <label for="other"> Other</label><br>
 
</div>
</body>
</html>

Output:

How many cats do you have?





Note: The for attribute of must be equal to the id attribute of the related elements to link them together.

Attributes:

for (value- element_id) – defines the id of the form element the label should be bound to.

form (value- form_id) – defines which form the label belongs to.

Enjoy coding!