Can I use label element with select?

P K picture P K · Apr 12, 2012 · Viewed 43k times · Source

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>

Answer

ThiefMaster picture ThiefMaster · Apr 12, 2012

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