HTML Tutorial
The <optgroup>
tag groups related options within a <select>
element. It's used to organize and categorize options, making it easier for users to navigate a large list of choices.
<!-- Basic optgroup -->
<select>
<optgroup label="Colors">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</optgroup>
<optgroup label="Shapes">
<option value="circle">Circle</option>
<option value="square">Square</option>
<option value="triangle">Triangle</option>
</optgroup>
</select>
<!-- Disabled optgroup -->
<select>
<optgroup label="Disabled" disabled>
<option value="disabled1">Disabled Option 1</option>
<option value="disabled2">Disabled Option 2</option>
</optgroup>
</select>
Exploring the <optgroup>
Tag
<select>
element and add some <option>
elements.<optgroup>
elements within the <select>
element.label
attribute on each <optgroup>
to specify its label text.disabled
attribute on <optgroup>
to disable all options within that group.label
attribute to provide clear and descriptive text for each optgroup, aiding screen readers and improving user comprehension.