Reputation: 1137
Do we need to use always the for attribute to associate input element to a label or keeping input element inside the label also fine?
I want to know what is the best practice and whether it is valid to wrap like that.
Upvotes: 1
Views: 1621
Reputation: 201876
It is valid to wrap input
inside label
, and by the specifications, it associates the label text with the control. However, browser support is better for the approach where the association is explicit with id
and for
attribute, so doing so is the best practice.
Upvotes: 2
Reputation: 586
They work exactly the same. Also, the standard accepts both : http://www.w3schools.com/tags/tag_label.asp
Upvotes: 1