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
?
@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.
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!
You should nest the input elements within the label elements.
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.
<!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.
With strict validation you need a block element around your input fields;
Best choice here would be to go with a <fieldset>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With