What is the <optgroup> element in HTML?
In HTML, the <optgroup> element is used to create a drop-down list. It groups related options in a <select> element.
Syntax
<optgroup disabled label=""><option></option></optgroup>
This syntax contains the following attributes:
-
disabled: This is a boolean attribute and specifies if an option-group should be disabled. If it is set, none of the items in this option-group are selectable. This makes browsers unable to receive any focus- related events like mouse clicks. -
label: This takestextas value. It specifies the name of the group of options. This attribute is mandatory if this element is used. -
<optgroup>: Elements may not be nested.
Example
The following code demonstrates the usage of the <optgroup> element in HTML.
The content that we want to be displayed as option-groups is written within the opening and closing tags <optgroup> and </optgroup>.