Forms & Inputs

HTML <optgroup> Tag

The <optgroup> tag is used to group related options in a <select> element (drop-down list).

Definition and Usage

The <optgroup> tag is used to group related options in a <select> element (drop-down list).

Standard Syntax:<optgroup>...</optgroup>

Interactive ExampleRunnable

HTML <optgroup> Example

html
Try it Yourself
Live code demonstration for the <optgroup> tag. Click "Try it Yourself" to edit and experiment in real time.
<div style="font-family: system-ui, sans-serif; padding: 16px; background: #ffffff; border-radius: 8px; border: 1px solid #e2e8f0; color: #0f172a;">
<label for="cars">Choose a car:</label>
<select  
    name="cars" id="cars">

       
      <optgroup label="Swedish Cars">

         
      <option value="volvo">Volvo</option>

         
      <option value="saab">Saab</option>

       
      </optgroup>

       
      <optgroup label="German Cars">

         
      <option value="mercedes">Mercedes</option>

         
      <option value="audi">Audi</option>

       
      </optgroup>

      </select>
</div>

Attributes for <optgroup>

2 Supported Attributes
AttributeValuesDefaultDescription
disableddisablednoneSpecifies that an option-group should be disabled
labeltextnoneSpecifies a label for an option-group
Global Attributes

The <optgroup> tag also supports the standard global attributes in HTML, including class, id, style, title, hidden, and data-*.

HTML Global Attributes Reference →
Event Attributes

The <optgroup> tag supports event attributes in HTML, such as onclick, onmouseover, onfocus, and more.

HTML Event Attributes Reference →

Browser Compatibility

ChromeEdgeFirefoxSafariOpera

More Tags in Forms & Inputs

View All 123Tags →