HTML optgroup element

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

Example

<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
   <optgroup>

Try </>

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

Related tags

TagsDescription
<select> select tag offers a list of pre-defined options.
<select> <option> .... </option> </select>
<option> option element defines option as a part of option list.
<select> <option> .... </option> </select>

Tag omission

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

Global Attributes

All the global attributes are applicable on the optgroup element.

Specific Attributes

<optgroup> tag attributes

AttributesDescription
disabled disabled attribute makes optgroup element uneditable and unprocessable. It disables a group of options.
<optgroup disabled> <option> .... </option> </optgroup>
label label attribute specifies a common name to a group of options.
<optgroup label="text"> <option> .... </option> </optgroup>


Was this article helpful?

 

Email:

Message:

Get the newsletter