HTML reference

optgroup

The <optgroup> element groups related <option> elements inside a <select>, giving each category a label.

What you will learn

  • How optgroup organizes choices
  • How label, option, and select relate
  • How grouping can make a long list easier to use

Basic example

<label for="car">Choose a car</label>
<select id="car" name="car">
  <optgroup label="Electric">
    <option value="compact-ev">Compact EV</option>
    <option value="family-ev">Family EV</option>
  </optgroup>
  <optgroup label="Hybrid">
    <option value="hybrid-sedan">Hybrid sedan</option>
  </optgroup>
</select>

The group label helps users understand the category while each option supplies the value that is submitted. The label on the select itself still matters.

Useful details

Related pages