The HTML label attribute
Quick answer
The HTML label attribute gives a user-readable label for the group or option. It is used on the <optgroup> and <option> elements.
Overview
The label attribute labels an option group or option. It is used on the <option> and <optgroup> elements.
It configures the choices in a drop-down — labeling option groups and pre-selecting a default. These sit inside a <select>.
Syntax
<optgroup label="Fruit"><option>Apple</option></optgroup>
Values
| Value |
|---|
| A string of label text. |
Example
<select><optgroup label="Fruit"><option>Apple</option><option>Pear</option></optgroup></select>
Best practices
Frequently asked questions
What does the label attribute do?
Labels an option group or option.
How do I group options in a drop-down?
Which elements use the label attribute?
It is an element-specific attribute, used on the <option> and <optgroup> elements.