HTML label attribute

label attribute defines the user visible value of options. It also specifies a common name for a group of options in <optgroup> element.

<p>If you are given a chance to visit one of the following countries, then what will be your choice?</p>
 <select>
  <option label="United States">
  <option label="Canada">
  <option label="China">
  <option label="Australia">
 </select>
</>

If you are given a chance to visit one of the following countries, then what will be your choice?

Attribute values

All possible values of label attribute

The value of label attribute is simple text.

Related Tags

The tags that support label attribute

<option> tag

<option> tag represents an option in an option list. label attribute provides caption or label for the option.

<select>
 <option label="subject1">
 <option label="subject2">
 <option label="subject3">
</select>
Try</>

It indicates that value of label attribute serves as the content of options.

<optgroup> tag

optgroup tag groups a list of options. label attribute represents the common name (user visible) for a group of options.

<select name="Subjects">
 <optgroup label="Chemistry">
  <option value="1"> Organic chemistry
  <option value="2"> Inorganic chemisry
  <option value="3"> Applied chemistry
 </optgroup>
 <optgroup label="Mathematics">
  <option value="1"> Sat1 
  <option value="2"> Calculus2 
  <option value="3"> Linear Algebra
 </optgroup>
</select>
Try</>

In the above example, label attribute defines the Chemistry and Mathematics names for two groups.



Was this article helpful?