Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it necessary to put INPUT elements in a DIV element?

Tags:

html

Why this give error in W3c html validation ? I'm using HTML 4.01 Strict doctype.

<form method="get" action="/search" id="search">

   <input type="text" value="search" maxlength="80" class="textbox" >

</form>

and this does not?

  <form method="get" action="/search" id="search">
    <div>
       <input type="text" value="search" maxlength="80" class="textbox" >
    </div>
  </form>

This is error

document type does not allow element "INPUT" here; missing one of "P", "H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV", "ADDRESS" start-tag

Is it necessary to put input in a div?

like image 525
Jitendra Vyas Avatar asked Jan 24 '10 12:01

Jitendra Vyas


People also ask

Should I put a form in a div?

@KickButtowski A form inside a div is no problem at all. You can try it yourself at a HTML validator. Besides, it is almost inevitable these days, since the modern pages are build on div's. If it was not allowed, a simple wrapper or placing the form in a container would already make the page invalid.

What can I put inside a div?

The <div> tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript. The <div> tag is easily styled by using the class or id attribute. Any sort of content can be put inside the <div> tag!

Should input be nested in label?

You should nest the input elements within the label elements.

Does input include inside label?

It is conventional to place the label on the right-hand side of the input for checkboxes and radio buttons. This can be done by placing the label after the input in the HTML, ensuring the DOM and visual order match.


2 Answers

<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->

A form can contain a block element (with the exception of another form) or a script element.

An input is not a block element, but most block elements may contain inline elements, which include inputs.

like image 53
Quentin Avatar answered Nov 15 '22 08:11

Quentin


With strict validation you need a block element around your input fields; Best choice here would be to go with a <fieldset>.

like image 21
fijter Avatar answered Nov 15 '22 09:11

fijter