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>
  <option label="United States">
  <option label="Canada">
  <option label="China">
  <option label="Australia">
Try </>

label attribute values

The value of label attribute is simple text.

Related Tags

The tags which support this attribute are as follows.

<option> tag

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


 <option label="subject1">
 <option label="subject2">
 <option label="subject3">

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 label="Mathematics">
  <option value="1"> Sat1 
  <option value="2"> Calculus2 
  <option value="3"> Linear Algebra

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

Was this article helpful?




Get the newsletter