Web/HTML/Element/optgroup

From Get docs


The HTML <optgroup> element creates a grouping of options within a <select> element.


The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

Content categories None.
Permitted content Zero or more <option> elements.
Tag omission The start tag is mandatory. The end tag is optional if this element is immediately followed by another <optgroup> element, or if the parent element has no more content.
Permitted parents A <select> element.
Implicit ARIA role group
Permitted ARIA roles No role permitted
DOM interface HTMLOptGroupElement

Note: Optgroup elements may not be nested.

Attributes

This element includes the global attributes.

disabled
If this Boolean attribute is set, none of the items in this option group is selectable. Often browsers grey out such control and it won't receive any browsing events, like mouse clicks or focus-related ones.
label
The name of the group of options, which the browser can use when labeling the options in the user interface. This attribute is mandatory if this element is used.

Examples

<select>
  <optgroup label="Group 1">
    <option>Option 1.1</option>
  </optgroup> 
  <optgroup label="Group 2">
    <option>Option 2.1</option>
    <option>Option 2.2</option>
  </optgroup>
  <optgroup label="Group 3" disabled>
    <option>Option 3.1</option>
    <option>Option 3.2</option>
    <option>Option 3.3</option>
  </optgroup>
</select>

Result

Specifications

Specification Status Comment
HTML Living StandardThe definition of '<optgroup>' in that specification. Living Standard
HTML5The definition of '<optgroup>' in that specification. Recommendation
HTML 4.01 SpecificationThe definition of '<optgroup>' in that specification. Recommendation

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
optgroup Chrome

Full support 1

Edge

Full support 12

Firefox

Full support 1

IE

Full support 5.5

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support 4

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

disabled Chrome

Full support 1

Edge

Full support 12

Firefox

Full support 1

IE

Full support 8

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support 4

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

label Chrome

Full support 1

Edge

Full support 12

Firefox

Full support 1

IE

Full support 5.5

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support Yes

Chrome Android

Full support Yes

Firefox Android

Full support 4

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support Yes

Legend

Full support  
Full support


See also