Optgroup

<optgroup>: The Option Group element #

::: section-content The <optgroup> HTML element creates a grouping of options within a <select> element. :::

Try it #

::: section-content ::: iframe ::: {.output-header .border-rounded-top}

HTML Demo: <optgroup> #

Reset :::

::: {#warning-no-script .warning-container} ::: warning The interactive example cannot be shown because JavaScript is disabled. ::: :::

::: {#warning-mathml-not-supported .warning-container .hidden} ::: warning The interactive example cannot be shown because MathML is not supported by your browser. ::: :::

::: {#editor-container .editor-container .tabbed-standard .hidden .border-rounded-bottom editor-type=“tabbed”} ::: {#tab-container .section .tabs} ::: {#tablist .tab-list role=“tablist”} HTML

CSS

JavaScript :::

::: {#html-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“html” aria-hidden=“true”} ::: {#html-editor} ::: :::

::: {#css-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“css” aria-hidden=“true”} ::: {#css-editor} label { display: block; margin-bottom: 10px; } ::: :::

::: {#js-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“js” aria-hidden=“true”} ::: {#js-editor} ::: ::: :::

::: {#output .output-container}

Output #

::: :::

::: {.section .console-container .hidden aria-hidden=“true”}

Console Output #

![] clear console

::: {#console .console} ::: :::

::: {#html-output .output .editor-tabbed} %html-content% ::: :::

::: {#sect1 .notecard .note} Note: Optgroup elements may not be nested. ::: :::

Attributes #

::: section-content 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 #

::: section-content ::: code-example [html]{.language-name}

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

::: section-content ::: {#sect2 .code-example} ::: iframe ::: ::: :::

Technical summary #

::: section-content

Content categoriesNone.
Permitted contentZero or more <option> elements.
Tag omissionThe 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 parentsA <select> element.
Implicit ARIA rolegroup
Permitted ARIA rolesNo role permitted
DOM interfaceHTMLOptGroupElement
:::

Specifications #

::: _table #

Specification #

HTML Standard
[# the-optgroup-element]{.small}


:::

Browser compatibility #

::: _table Desktop Mobile


           Chrome    Edge   Firefox   Internet Explorer   Opera   Safari   WebView Android   Chrome Android   Firefox for Android   Opera Android   Safari on IOS   Samsung Internet

optgroup 1 12 1 5.5 15 ≤4 4.4 18 4 14 ≤3.2 1.0 disabled 1 12 1 8 15 ≤4 4.4 18 4 14 ≤3.2 1.0 label 1 12 1 5.5 15 ≤4 4.4 18 4 14 ≤3.2 1.0 :::

See also #

::: section-content

::: _attribution © 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/optgroup{._attribution-link} :::