HTML `optgroup` Element: Grouping Options in Select Lists for Enhanced Usability
Learn how to improve the organization and user experience of your HTML select lists using the `optgroup` element. This tutorial demonstrates grouping related options for better readability and easier selection, especially in long dropdown lists.
Using the HTML `
Understanding the `
The HTML `
Using the `
The `
Example: Using `
<select>
<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>
Browser Support for `
The `
| Browser | Support |
|---|---|
| Chrome | Yes |
| Edge | Yes |
| Firefox | Yes |
| Opera | Yes |
| Safari | Yes |
Attributes of the `
| Attribute | Value | Description |
|---|---|---|
disabled |
disabled |
Disables the entire group. |
label |
Text | Specifies a label for the option group. |
The `