Home HTML Tags <optgroup> HTML optgroup Tag Definition
Definition and Usage The <optgroup> element groups related <option> elements inside a <select> . The browser shows a non-selectable heading from the label attribute.
Use groups when a long dropdown has clear categories (cities by country, products by type). Always set label — it is required for optgroup. Do not nest one optgroup inside another.
Baseline · Widely available. Not deprecated. Core support since about July 2015. Some newer customizable-select extras have uneven support.
Newer / uneven support. In customizable <select> UIs, a <legend> may appear inside optgroup for a styleable label. Stick to the label attribute for broad compatibility.
Syntax
HTML Syntax <select>
<optgroup label="Group name">
<option>Choice</option>
</optgroup>
</select> Start tag required. End tag is best practice (omission is allowed only in narrow cases). Parent must be <select>. Implicit ARIA role is group.
Reference
Attributes The attributes you will use on <optgroup>:
Attribute Description Notes labelName of the option group shown in the UI Required when using optgroupdisabledBoolean — none of the group’s options are selectable Browsers typically gray the group out
Try it
Live Preview Toggle a group between enabled and disabled. Open the select to compare.
Code
HTML Examples Short, copy-ready snippets. Use Try It Yourself for a live editor.
1. Basic groups 2. Disabled group 3. Labeled select 4. Mixed options Example 1 — Group Related Options Split a long list into labeled categories.
<label for="dino">Choose a dinosaur:</label>
<select id="dino">
<optgroup label="Theropods">
<option>Tyrannosaurus</option>
<option>Velociraptor</option>
<option>Deinonychus</option>
</optgroup>
<optgroup label="Sauropods">
<option>Diplodocus</option>
<option>Saltasaurus</option>
<option>Apatosaurus</option>
</optgroup>
</select> Choose a dinosaur: Tyrannosaurus Velociraptor Deinonychus Diplodocus Saltasaurus Apatosaurus
How It Works Wrap choices in <select> as usual.Add <optgroup label="…"> for each category.Put <option> elements inside that group only.Open the control — group titles appear but are not selectable.Example 2 — Disable a Whole Group Block every option in a category with one attribute.
<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>
</optgroup>
</select> Pick an option Option 1.1 Option 2.1 Option 2.2 Option 3.1 Option 3.2
Group 3 options are visible but not selectable.
How It Works Keep normal groups without disabled.Add disabled on the group you want to lock.All options in that group become non-selectable.Users still see the labels — useful for “coming soon” categories.Example 3 — Accessible Field Label Pair the select with a <label>; keep each group’s label attribute too.
<label for="city">Shipping city</label>
<select id="city" name="city">
<optgroup label="India">
<option value="maa">Chennai</option>
<option value="bom">Mumbai</option>
</optgroup>
<optgroup label="USA">
<option value="nyc">New York</option>
<option value="sfo">San Francisco</option>
</optgroup>
</select> Shipping city Chennai Mumbai New York San Francisco
How It Works Connect <label for> to the select’s id.Set each group label (country names here).Give options a value for form submission.Screen readers get both the field name and the group headings.Example 4 — Ungrouped Option Plus Groups A placeholder (or common choice) can sit outside any optgroup.
<label for="fruit">Favorite fruit</label>
<select id="fruit">
<option value="">-- Choose --</option>
<optgroup label="Citrus">
<option>Orange</option>
<option>Lemon</option>
</optgroup>
<optgroup label="Berries">
<option>Strawberry</option>
<option>Blueberry</option>
</optgroup>
</select> Favorite fruit -- Choose -- Orange Lemon Strawberry Blueberry
How It Works Place a standalone <option> before the groups (placeholder).Follow with one or more optgroups .Keep groups flat — no nesting.Users pick either the placeholder or a grouped choice. Edge Cases & Pitfalls Most optgroup mistakes are missing label, nesting groups, or over-grouping short lists.
required Always set label The label attribute is mandatory on optgroup. Without it, the group has no proper heading.
nesting No nested optgroups Do not put <optgroup> inside another <optgroup>. Keep a single grouping level.
parent Only inside select optgroup belongs under <select> , not under datalist or arbitrary containers.
heading Group title is not a value Users cannot select the group label itself — only the option items inside.
design Don’t over-group A handful of options often needs no groups. Use optgroup when categories help scanning.
Compatibility
Browser Support The <optgroup> element is core HTML for select controls in every browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
<optgroup> Widely available since about July 2015 (and long before). label and disabled work across modern browsers; customizable-select extras vary.
97% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Supported optgroup Widely supported
Bottom line: Safe to use. Always set label, never nest groups, and prefer plain options for short lists.
Remember
Key Takeaways Role: group related options inside a select.
label: required — names the non-selectable group heading.
disabled: locks every option in that group.
Flat only: never nest optgroup elements.
One line: use optgroup label="…" to categorize select options — never nest, always label.
UA style
Default CSS Settings Typical user-agent defaults (exact values vary by browser):
optgroup {
font-weight: bolder;
}
/* Appearance of the group heading is mostly
controlled by the browser's select UI */ Native select styling is limited. Focus on clear label text more than CSS.
Frequently Asked Questions What does the HTML optgroup tag do? The optgroup element groups related option elements inside a select. Browsers show a non-selectable group heading from the label attribute.
Is the label attribute required? Yes. When you use optgroup, the label attribute is mandatory — it names the group in the UI.
Can I nest optgroup elements? No. Optgroups must not be nested. Keep one level of groups under select.
What does disabled do on optgroup? If disabled is set, none of the options in that group can be selected. Browsers usually gray the group out.
Where can optgroup appear? As a child of select. Its children are option elements (and, in newer customizable selects, optionally a legend).
Should every select use optgroup? Only when options form clear categories. Short flat lists are fine without groups.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
12 people found this page helpful
Helpful Share Copy link Suggestion