HTML <optgroup> Tag

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 2 Examples
HTML5 Forms

What You’ll Learn

The <optgroup> tag structures select menus by grouping related options. This guide covers syntax, the label attribute, common form patterns, and accessibility for beginners.

01

Option Groups

Label categories in dropdowns.

02

Inside select

Child of select only.

03

label Attribute

Group heading text.

04

option Items

Choices inside each group.

05

Categorizing

Fruits, vegetables, regions.

06

Better UX

Easier option discovery.

What Is the <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.

Valid HTML5 — Child of <select> Only

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

📝 Syntax

Place <optgroup> inside <select> and nest <option> elements inside each group:

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

Syntax Rules

  • Parent must be a select element.
  • Children must be option elements (not other optgroups).
  • label attribute is required and defines the group heading.
  • Options outside any optgroup are still valid for ungrouped items.

⚡ Quick Reference

TopicCode SnippetNotes
Basic group<optgroup label="Name">Inside select
Options<option value="...">Inside optgroup
Disable groupdisabledAll options disabled
Parent<select>Required container
Ungrouped option<option> in selectNo optgroup wrapper
Browser supportUniversalAll major browsers

⚖️ Grouped vs Flat <select>

ApproachStructureBest For
optgroupLabeled categories of optionsMany related choices
Flat optionsOptions directly in selectShort simple lists
optionIndividual selectable itemBoth approaches

🧰 Attributes

The <optgroup> tag supports the label attribute, which defines the heading displayed above options in that group:

attributes.html
<optgroup label="Group Name">
  <!-- Options go here -->
</optgroup>
label Required

Defines the group heading shown in the dropdown (not selectable).

label="Fruits"
disabled Optional

Disables every option inside the group.

<optgroup disabled>

Examples Gallery

Categorize dropdown options and improve form usability with labeled option groups.

👀 Live Preview

Open the dropdown to see labeled option groups:

📚 Common Use Cases

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.

Categorizing Options

Organize related choices under clear group labels such as food categories or geographic regions.

categorizing-options.html
<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>
Try It Yourself

Enhancing User Experience

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.

  • Group countries by continent instead of one alphabetical list.
  • Separate clothing sizes by region (US, UK, EU).
  • Use disabled on optgroup when an entire category is unavailable.

♿ Accessibility

  • Label the select — Use <label for="id"> on the parent select, not on optgroup.
  • Group labels — The label attribute is exposed to assistive technology as a group name.
  • Meaningful option text — Each option should describe the choice clearly.
  • Avoid huge lists — Even with groups, consider autocomplete patterns for 50+ items.

🧠 How <optgroup> Works

1

Author builds select

Create a select and add optgroup sections.

Markup
2

Label displays

Browser shows group headings as non-selectable labels in the menu.

Rendering
3

User picks option

Only option values are submitted with the form.

Interaction
=

Organized dropdown

Users find the right choice faster in categorized select menus.

Browser Support

The <optgroup> tag is supported in all major browsers including Internet Explorer.

Baseline · HTML4 / HTML5

Universal optgroup support

Grouped options render consistently in Chrome, Firefox, Safari, Edge, Opera, and Internet Explorer.

100% Core tag support
Google Chrome Fully supported
Full support
Mozilla Firefox Fully supported
Full support
Apple Safari Fully supported
Full support
Microsoft Edge Fully supported
Full support
Internet Explorer Fully supported · EOL
Full support
Opera Fully supported
Full support
<optgroup> tag 100% supported

Bottom line: Use <optgroup> confidently to organize select menus in any browser.

Conclusion

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.

💡 Best Practices

✅ Do

  • Group options when lists are long or logical
  • Write clear, concise optgroup labels
  • Test select menus across browsers
  • Label the parent select for accessibility

❌ Don’t

  • Use optgroup outside select
  • Nest optgroup inside optgroup
  • Use vague labels like “Group 1”
  • Overload dropdowns with 100+ ungrouped items

Key Takeaways

Knowledge Unlocked

Six truths every developer should know about <optgroup>

Bookmark these before you build dropdown forms.

6
Core concepts
📝 02

Inside select

Valid only as select child.

Structure
⚙️ 03

label Attribute

Group heading (required).

Attributes
📋 04

option Children

Selectable choices inside.

Markup
👤 05

Better UX

Faster option scanning.

Forms
🌐 06

100% Support

All major browsers.

Compatibility

❓ Frequently Asked Questions

It groups related option elements inside a select dropdown with labeled categories.
Inside a select element, wrapping option elements.
label (required) and disabled (optional).
No. optgroup cannot contain another optgroup—only option elements.
optgroup is a labeled container; option is the selectable item.

Organize Your Dropdowns

Practice <optgroup> with labeled categories in the Try It editor.

Try Categorizing Options →

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.

6 people found this page helpful