HTML optgroup element

HTML <optgroup> tag groups all the option elements under a common name. We have to select one out of these options.

<p>Choose the course you would like to teach.</p>
   <optgroup label="Chemistry">
    <option value="1"> Organic chemistry
    <option value="2"> Inorganic chemisry
    <option value="3"> Applied chemistry

Choose the course you would like to teach.

Here, the value of the label attribute in optgroup starting tag serves as the title of a group of options.

Tag omission

The end tag of <optgroup> element may be omitted.

Global Attributes

All the global attributes are applicable on the optgroup element.

Tag Attributes

Attributes that are applicable to <optgroup> tag

disabled attribute makes optgroup element uneditable and unprocessable. It disables a group of options.

<optgroup disabled> <option> .... </option> </optgroup>

label attribute specifies a common name to a group of options.

<optgroup label="text"> <option> .... </option> </optgroup>

Was this article helpful?