👀 Live Preview
Open the dropdown to see labeled option groups:

The <optgroup> tag structures select menus by grouping related options. This guide covers syntax, the label attribute, common form patterns, and accessibility for beginners.
Label categories in dropdowns.
Child of select only.
Group heading text.
Choices inside each group.
Fruits, vegetables, regions.
Easier option discovery.
<optgroup> Tag?The <optgroup> tag is an HTML element designed for use within <select> elements. It groups related <option> elements together, providing a hierarchical structure within a dropdown list.
<optgroup> cannot be used outside a select element. Each group wraps one or more option elements and displays a non-selectable label heading in the menu.
Place <optgroup> inside <select> and nest <option> elements inside each group:
<select>
<optgroup label="Group 1">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</optgroup>
<optgroup label="Group 2">
<option value="option3">Option 3</option>
<option value="option4">Option 4</option>
</optgroup>
</select>select element.option elements (not other optgroups).label attribute is required and defines the group heading.| Topic | Code Snippet | Notes |
|---|---|---|
| Basic group | <optgroup label="Name"> | Inside select |
| Options | <option value="..."> | Inside optgroup |
| Disable group | disabled | All options disabled |
| Parent | <select> | Required container |
| Ungrouped option | <option> in select | No optgroup wrapper |
| Browser support | Universal | All major browsers |
<select>| Approach | Structure | Best For |
|---|---|---|
optgroup | Labeled categories of options | Many related choices |
| Flat options | Options directly in select | Short simple lists |
option | Individual selectable item | Both approaches |
The <optgroup> tag supports the label attribute, which defines the heading displayed above options in that group:
<optgroup label="Group Name">
<!-- Options go here -->
</optgroup>label RequiredDefines the group heading shown in the dropdown (not selectable).
label="Fruits"disabled OptionalDisables every option inside the group.
<optgroup disabled>Categorize dropdown options and improve form usability with labeled option groups.
Open the dropdown to see labeled option groups:
Use <optgroup> to categorize options in dropdown menus and improve the overall user experience by making it easier to locate and select the desired choice.
Organize related choices under clear group labels such as food categories or geographic regions.
<select>
<optgroup label="Fruits">
<option value="apple">Apple</option>
<option value="orange">Orange</option>
</optgroup>
<optgroup label="Vegetables">
<option value="carrot">Carrot</option>
<option value="broccoli">Broccoli</option>
</optgroup>
</select>By grouping related options together, optgroup helps users scan long dropdowns faster. Pair grouped selects with a descriptive label on the select element and meaningful option text for clarity.
disabled on optgroup when an entire category is unavailable.<label for="id"> on the parent select, not on optgroup.label attribute is exposed to assistive technology as a group name.option should describe the choice clearly.Create a select and add optgroup sections.
Browser shows group headings as non-selectable labels in the menu.
Only option values are submitted with the form.
Users find the right choice faster in categorized select menus.
The <optgroup> tag is supported in all major browsers including Internet Explorer.
Grouped options render consistently in Chrome, Firefox, Safari, Edge, Opera, and Internet Explorer.
Bottom line: Use <optgroup> confidently to organize select menus in any browser.
The <optgroup> tag is a valuable tool for enhancing the organization and usability of select menus in HTML forms. By implementing this tag thoughtfully, you can create more intuitive and user-friendly interfaces.
<optgroup>Bookmark these before you build dropdown forms.
Labeled categories in select.
BehaviorValid only as select child.
StructureGroup heading (required).
AttributesSelectable choices inside.
MarkupFaster option scanning.
FormsAll major browsers.
Compatibilityselect element, wrapping option elements.label (required) and disabled (optional).optgroup is a labeled container; option is the selectable item.Practice <optgroup> with labeled categories in the Try It editor.
6 people found this page helpful