You can renounce to the label
attribute and set instead a disabled <option>
as first element within your <optgroup>
, and then style this option.
<select>
<option>1. One</option>
<option>2. Two</option>
<optgroup>
<option disabled style="background:#dfb;color:#555;position:relative;top:-0.7em">3. Three</option>
<option>3.1 Three dot one</option>
<option>3.2 Three dot two</option>
</optgroup>
<option>4. Four</option>
</select>
additional tips:
If you don't need the <optgroup>
in itself, a variant is just using the disabled option(s), which up to a certain extent will visually will emulate the optgroups by creating sections in your list.
For aesthetic reason, if you use the disabled option within an optgroup, I recommend slighly moving it upward with position:relative;top:-0.7em
.