🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEhtml

html Documentation

LOADING ENGINE...

HTML <optgroup> Tag

Group options in dropdowns. Learn optgroup structure and organization.

optgroup.html
<!-- Optgroup -->
<select>
<optgroup label="Fruits">
<option>Apple</option>
<option>Banana</option>
</optgroup>
</select>
📦
optgroup.html
1 / 7
📦

TutorThe <optgroup> tag groups related options inside a <select> dropdown. It helps organize long lists of options into logical categories. The label attribute provides the group heading that users see.

Optgroup Mastery

Unlock nodes by learning optgroup and select structure.

Concept 1: The Optgroup Tag

The <optgroup> tag groups related options inside a <select> dropdown. It helps organize long lists of options into logical categories. The label attribute provides the group heading that users see.

System Check

Which element groups options inside a select?

Community Holo-Net

Share Optgroup Designs

Created effective optgroups? Share your code and grouping strategies.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

HTML <optgroup> Tag Documentation

Author

Pascual Vila

Frontend Instructor.

The <optgroup> tag groups related options inside a <select> dropdown. It helps organize long lists of options into logical categories. The label attribute provides the group heading that users see.

Structure and Attributes

  • The <optgroup> tag must be strictly inside a <select> element.
  • It contains one or more <option> elements representing selectable items.
  • The label attribute is required and displays as a non-selectable group header.
  • Options inside the group are indented and grouped together visually by the browser.

Common Use Cases

Common use cases include:

  • Geographical Data: Organizing countries by region.
  • E-commerce: Grouping products by category.
  • Food & Beverage: Separating menu items by type (drinks, main courses, desserts).

Optgroups heavily improve UX by making long dropdown menus more navigable and structured.

Best Practices

  • Use <optgroup> primarily to organize lists with more than 10 options.
  • Always include a descriptive label attribute.
  • Group related options based on the user's expected mental model.

Optgroup Tag Glossary

<optgroup>
HTML element that groups related options inside a <select> dropdown. Requires a label attribute.
label Attribute
Required attribute on <optgroup> providing the unselectable group heading visible to users.
<select>
HTML element forming the dropdown menu container holding <option> or <optgroup> elements.
<option>
HTML element representing an individual selectable choice inside a dropdown or optgroup.