Can I use label element with select?
Most of the places I see label example with input elements only.
What does standard say about label association?
Is it a valid HTML markup?
<label for="id_select"> Options </label> <select id="id_select" autofocus="true"> <option value="1"> Option1 </option> <option value="2"> Option2 </option> </select>
The <label> element is used to associate a text label with a form <input> field. The label is used to tell users the value that should be entered in the associated input field.
Select tag in HTML is used to display the selection list to choose one or multiple options from the selection list. <select> tag can be used with values like selected, required, disabled, required, autofill, autofocus, link, size, multiple, placeholder, optgroup, and many more.
Yes, it's valid and works fine.
This attribute explicitly associates the label being defined with another control.
http://www.w3.org/TR/html401/interact/forms.html#h-17.9.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With