Forms & Controls
HTML <optgroup> element
Groups options in a select under a shared label. It cannot contain nested optgroups in ordinary select markup. Use label to give a meaningful group name. A disabled group makes its options unavailable; it does not create a selectable heading. Customizable select markup has additional rules. It accepts global HTML attributes; individual global features may be inapplicable or restricted.
Formal Syntax & Structure
html syntaxhtml
<optgroup label="Group"> <option>Choice</option></optgroup>Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| disabled | boolean | Disables supported controls or elements. Disabled form controls are generally not focusable, validated or submitted. The exact effect depends on the element; disabled="false" still disables. |
| label | text | Supplies a human-readable label for optgroup, option or track. It is not the same as the label element used to name form controls. |
Return Value
HTMLOptGroupElement
Content model: Option elements and script-supporting elements; customizable select supports additional legend markup.
Working Example
Example Snippethtml
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>HTML example</title> </head> <body> <label> Book <select> <optgroup label="Fiction"> <option>Novel</option> </optgroup> <optgroup label="Nonfiction"> <option>History</option> </optgroup> </select> </label> </body></html>