HTML optgroup Tag

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

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.

HTML Syntax

syntax.html
<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.

Attributes

The attributes you will use on <optgroup>:

AttributeDescriptionNotes
labelName of the option group shown in the UIRequired when using optgroup
disabledBoolean — none of the group’s options are selectableBrowsers typically gray the group out

Global Attributes

The <optgroup> tag also supports the Global Attributes in HTML.

Live Preview

Toggle a group between enabled and disabled. Open the select to compare.

disabled on optgroup blocks every option in that group.

Select

Sauropods group is enabled

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Group Related Options

Split a long list into labeled categories.

HTML
<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>
Try It Yourself

How It Works

  1. Wrap choices in <select> as usual.
  2. Add <optgroup label="…"> for each category.
  3. Put <option> elements inside that group only.
  4. 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.

HTML
<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>
Try It Yourself

How It Works

  1. Keep normal groups without disabled.
  2. Add disabled on the group you want to lock.
  3. All options in that group become non-selectable.
  4. 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.

HTML
<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>
Try It Yourself

How It Works

  1. Connect <label for> to the select’s id.
  2. Set each group label (country names here).
  3. Give options a value for form submission.
  4. 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.

HTML
<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>
Try It Yourself

How It Works

  1. Place a standalone <option> before the groups (placeholder).
  2. Follow with one or more optgroups.
  3. Keep groups flat — no nesting.
  4. 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.

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.

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.

Default CSS Settings

Typical user-agent defaults (exact values vary by browser):

default.css
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

The optgroup element groups related option elements inside a select. Browsers show a non-selectable group heading from the label attribute.
Yes. When you use optgroup, the label attribute is mandatory — it names the group in the UI.
No. Optgroups must not be nested. Keep one level of groups under select.
If disabled is set, none of the options in that group can be selected. Browsers usually gray the group out.
As a child of select. Its children are option elements (and, in newer customizable selects, optionally a legend).
Only when options form clear categories. Short flat lists are fine without groups.

Next: option

Define selectable choices with the HTML option element.

option tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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