Jukka K. Korpela schrieb:
[why is it not logical to have a input inside a label?]
Because an input field (control) is an element that exists in order to
accept user input, whereas a label element specifies a textual
explanation for an input field. So an input is not logically a part (a
component) of a label.
While this is correct, it raises the question why the W3C chose to allow
the nested variant then.
Indeed. It seems to add to the complexity of the language - not much,
but without any gain except minor convenience in authoring. Anyway, HTML
4.01 presents the explicit association first and uses it in all examples.
It would have been more logical to make the
label an attribute of the input field.
In a sense yes, and for <input type=submit> and <input type=button>, it
_is_ possible: the value="..." attribute acts as a label. The HTML 4.01
spec even refers them as labels:
"Some form controls automatically have labels associated with them
(press buttons) while most do not (text fields, checkboxes and radio
buttons, and menus)."
http://www.w3.org/TR/html401/interact/forms.html#h-17.9
But extending such usage would extend the questionable use of attributes
to carry content. On the practical side, it would limit labels to plain
text - which is often mentioned as a problem with buttons.
On the other hand, both the label and the input field together form a
semantic unit, so it would be good if there was an element like,
perhaps, <formfield> which could contain an input element (or even
several) as well as its (their) label.
Yes, that would be natural. But then something else (like association
with for and id attributes) would still be needed in cases where the
label and the input field cannot be wrapped in the same container (e.g.,
when they are in different columns of a table).