I've been reading the w3.org HTML5 form spec, and was surprised to see the following HTML:
<p><label>Customer name: <input name="custname"></label></p>
<p><label>Telephone: <input type=tel name="custtel"></label></p>
<p><label>E-mail address: <input type=email name="custemail"></label></p>
Semantically, this confuses me. Wouldn't a <label>
make more sense as a sibling to an <input>
, rather than as its parent?
In the wild, I'm more used to seeing the following configuration:
<p>
<label for="customer_name">Customer name:</label>
<input id="customer_name" name="customer[name]">
</p>
I know that a large majority of markup out there is malformed, but I'm interested to hear others' thoughts on what the proper convention should be.
I stand corrected, but it seems every markup generator and form helper I've used essentially violates the W3's suggestions - even those that claim HTML5 support, making use of client-side validations and the like.
Thoughts?