views:

106

answers:

5

I thought that an html form has no effect on the layout of a page, and that it is just a way to group fields to send their values to the server in a single request.

However, I notices that when I remove the form tag, the layout changes.

Where can I find an explanation of visual effects of the <form> tag?

+1  A: 

Most browsers have DOM inspector tools that will show you the styles applied to a given element. Firebug is a good example.

In short, a form is an element that has display: block and may have margins / padding. (Plus whatever styles get applied from any author or user stylesheets)

David Dorward
+3  A: 

<form> is a block-level element, so at the very least, it will appear on its own line. It probably also has some basic margin and padding attributes as a default. I would recommend using Firebug to inspect the form element and see what it's layout properties are.

You can easily adjust the appearance of <form> through either an external css file, css in your document HEAD, or inline styles on the form, like this:

<form style="margin: 0; padding: 0; background-color: #cc5500;">
...
</form>
gravelpot
You can also make it appear inline by adding "display:inline;" in the style attribute/css class/tag.
Christopher Mahan
+1  A: 

The form element is a block-level element, so the element in itself will have layout properties.

Different browsers have different default styles (margin, padding, etc.) to form controls. One way to get around this is to use CSS resets, such as Eric Meyer's classic reset.css or a more styled CSS framework such as Tripoli.

Note that form controls are perfectly valid outside the form tag, for example in use as interface controls.

While the W3C documentation isn't always easy to read, it is the definitive text on HTML. See Forms in HTML documents.

Ilya
That bit about about form controls outside the form element is wrong. Form controls are entirely valid outside the form element. See http://mailmarkup.org/prettydiff/prettydiff.html which contains many form controls and no form elements. It passes 100% in every HTML validator.
Thanks for the correction Austin. You are entirely correct, and I was confusing the fact that some form controls wouldn't work properly in older browsers without a form container. I'll fix my answer.
Ilya
A: 

If you want to make sure you have a consistent layout with and without forms, use the following CSS:

form{
    margin:0;
    padding:0;
    display:block;
    }
Rowan
A: 

Form is a html block element. It acts like every html block. It can have some default style applied by default browser style, so it can be various depending on browser.

prostynick