by mattmanser · 10y ago · 0 comments
To me that's conceptually as well as semantically broken, the two are separate things why is the input inside the label? He's saying make everything semantic, and then semantically breaking forms.
Also if you have any inputs that don't have a label for whatever reason you either have to wrap them in them any way to get CSS to work or make sure you never rely on the input being nested in the label in your CSS.
And having them apart also makes it easier to design responsively if you want a side-by-side design for desktop vs a stacked design for mobile.
Saves having to add a for tag I guess.
I guess a lot of that article is opinion though, so you're always going to get people objecting to one point or another, though a lot of it seems sensible advice.
Edit, to add: To avoid nesting you can use the for attribute. More info on the following link addressing checkboxes and input nesting, in general:
<label for="coolInput">Click me:</label>
<input type="checkbox" id="coolInput" />
Edit: You edited while I was typing this out and added info about the `for` ;)The only exceptions to "each input must have a label" are inputs of type "hidden" and ones that make button controls so the value attribute effectively labels the control.
This matters more for touch screens, but I suspect most of the web is accessed at least sometimes through touch screens.
w3.org: The label element may contain at most one descendant input element, button element, select element, or textarea element.
You just have to be a bit careful with it concerning screen readers.
EDIT: besides, there are CSS reasons for wrapping the input with a label.
Skype Web puts a whole <form> in a <label>, I guess it is for that reason
Been developing websites for almost 15 years now, and I recall this always being a common thing to do.
> To me that's conceptually as well as semantically broken, the two are separate things why is the input inside the label?
I agree that it's conceptually broken, but it is not semantically broken -- since the HTML5 spec and screen readers all recognize this as an equally valid way to define a label on an input.
So they're both equally "correct", just a trade-off of ease-of-styling (for some designs) vs. saving a few bytes and mental overhead of assigning for/id attributes to them.