TIL of the selectopt group
POSTED ON:
TAGS: html forms selectors mdn codepen
You can create some cool dividers for your field options using the optgroup
element. MDN
<select>
<option>--Your Favourite Animal--</option>
<optgroup label="Birds">
<option>Blue Jay</option>
<option>Cardinal</option>
<option>Hummingbird</option>
</optgroup>
<optgroup label="Sea Creatures">
<option>Shark</option>
<option>Clownfish</option>
<option>Whale</option>
</optgroup>
<optgroup label="Mammals">
<option>Lion</option>
<option>Squirrel</option>
<option>Quokka</option>
</optgroup>
</select>
You can even disable the whole group using the disabled
attribute!
See the Pen Using the label Attribute with optgroup Elements by Smashing Magazine (@smashingmag) on CodePen.
Related TILs
Tagged: html