Alex Rivera | Logout

Why does the W3C advise wrapping input elements in <p> tags?

Asked 2011-08-03T23:17:50.067
37

I've seen a lot of examples on the web where forms are laid out like so:

<form>
    <p><input></p>
</form>

To my surprise, this is also described in the specification:

Any form starts with a form element, inside which are placed the controls. Most controls are represented by the input element, which by default provides a one-line text field. To label a control, the label element is used; the label text and the control itself go inside the label element. Each part of a form is considered a paragraph, and is typically separated from other parts using p elements. Putting this together, here is how one might ask for the customer's name:

Though this section is non-normative, it still seems to me that this is bad practice and not semantic. I suppose that the purpose is to put inputs on their own line, but shouldn't the display of these elements be controlled using CSS?

Is there a reason why the W3C advises forms be laid out this way? Am I missing something?

Edit
Report

1 Answer

1

This goes for HTML 4, but maybe not for the requested HTML 5.

Ref.: 17.3 The FORM element

form needs a block-level element as child. input is an inline element. The p does the trick.

answered 2011-08-03T23:20:55.520

Your Answer