Why does the W3C advise wrapping input elements in tags?

If you are writing a form in a meaningful (read: semantic) way, you will want the flow of text to lead to the element:

<form>
 <p><label for="firstName">Please enter your first name:</label><input id="firstName" type="text" /></p>
</form>

An even better way is to treat your form like a mad-libs script:

<form>
  <p>Hello. My <label for="firstName">name</label> is <input id="firstName" type="text" />...</p>
</form>

A p element isn’t the only way to mark-up a form. If a matrix of data is being added/edited, it’s semantically valid to use a table.

In other cases, you might not want to use a wrapping element. It depends on what content you want to be serving up. Worry about styling it all after you’ve got your content sorted out.

Leave a Comment

techhipbettruvabetnorabahisbahis forumu