**`<optgroup>`** organizes a long list of `<option>`s into labeled clusters within a `<select>`, using its **`label`** attribute for the group heading (the label itself isn't selectable — it's just a visual/structural divider). This is especially useful for dropdowns with many choices that naturally fall into categories, like car makes grouped by country, or products grouped by category.
1Understanding <optgroup>
`<optgroup>` organizes a long list of <option>s into labeled clusters within a <select>, using its `label` attribute for the group heading (the label itself isn't selectable — it's just a visual/structural divider). This is especially useful for dropdowns with many choices that naturally fall into categories, like car makes grouped by country, or products grouped by category.
The optgroup's label is purely a heading — it can't be selected as a value itself, so don't rely on it to represent a real 'category' choice; if users need to pick a category too, that requires its own separate control.
<select name="fruit">
<optgroup label="Citrus">
<option value="orange">Orange</option>
<option value="lemon">Lemon</option>
</optgroup>
<optgroup label="Berries">
<option value="strawberry">Strawberry</option>
</optgroup>
</select>2Practical Example
Here is a real-world application of <optgroup> showing how it is used in production HTML.
<!-- A disabled optgroup disables every option inside it -->
<optgroup label="Out of Stock" disabled>
<option value="x1">Item X1</option>
</optgroup>3Best Practices
Follow these guidelines when working with <optgroup>:
1. Use <optgroup> to organize long dropdowns into clear, labeled categories
2. Keep the label attribute short and purely descriptive of the group below it
3. Don't nest <optgroup> inside another <optgroup> — nesting isn't supported
Tip: The optgroup's label is purely a heading — it can't be selected as a value itself, so don't rely on it to represent a real 'category' choice; if users need to pick a category too, that requires its own separate control.
<select name="fruit">
<optgroup label="Citrus">
<option value="orange">Orange</option>
<option value="lemon">Lemon</option>
</optgroup>
<optgroup label="Berries">
<option value="strawberry">Strawberry</option>
</optgroup>
</select>