Two columns Three columns Mixed cols and rows Gallery Archives Clean & Clear Dark or Black High Contrast/ Impact Blog Designs New Corporate/ Professional Unconventional Designs Liquid layouts Web Design Firms Our Favorites What's Popular Last 20 submissions
Horizontal Menus Vertical Menus Multiple/ Nested Levels

CSS Examples Tableless forms using CSS

Date: 02/10/2005 Tableless forms using CSS

Author: CSS Drive

This CSS example transforms a conventional form so it's tableless. A form that doesn't use tables for its layout is much more lightweight and semantically correct.





The CSS:

<style type="text/css">

label{
float: left;
width: 120px;
font-weight: bold;
}

input, textarea{
width: 180px;
margin-bottom: 5px;
}

textarea{
width: 250px;
height: 150px;
}

.boxes{
width: 1em;
}

#submitbutton{
margin-left: 120px;
margin-top: 5px;
width: 90px;
}

br{
clear: left;
}

</style>

The HTML:

<form>

<label for="user">Name</label>
<input type="text" name="user" value="" /><br />

<label for="emailaddress">Email Address:</label>
<input type="text" name="emailaddress" value="" /><br />

<label for="comments">Comments:</label>
<textarea name="comments"></textarea><br />

<label for="terms">Agree to Terms?</label>
<input type="checkbox" name="terms" class="boxes" /><br />

<input type="submit" name="submitbutton" id="submitbutton" value="Submit" />

</form>

By floating the "label" tag to the left, the text description of each form field appears to the left, resulting in a "two column" look for the form. The width of the "label" is controlled, so it will comfortably contain the longest text description in the form. I throw in a <br> tag with "clear: left" after each form field to prevent the floating <label> tag from potentially spilling over to content beneath it. Margins such as "margin-top" and "margin-bottom" are also used to add some nice margins between form fields.

Comments (108)

Cool and Clear. Fine. Thanks.
Ruby

#1: ivan on 03/18 at 05:01 PM

It will not work on multicolumn based form layout.

#2: Ashish on 04/20 at 03:24 AM

gg amk dsaiuja akfdja

#3: ytu on 05/07 at 04:36 AM

What is the client side data gathering piece?

#4: Dale on 05/11 at 02:09 PM

it is a vv nice scc form

visit http://hanif.net.tc
e mail

#5: hanif on 05/27 at 03:10 AM

Hey this example is beautiful

#6: Arkos Noem Arenom on 07/04 at 04:16 PM

good work,thank_you

#7: scarty on 07/12 at 02:42 PM

nice website.. cheers !!!

#8: mikesapartment on 07/19 at 04:01 PM

Hello
Nice website

Cheers

#9: apartment on 07/19 at 04:03 PM

"Tables are certianly not the ideal solution."

Could you please explain why?!

That's exactly why tables are existing in HTML: to represent tabular data, like the form in this example.

I think you've misunderstood something very badly here. You should not use table element for layout design (header, footer, sidebars, menu, etc), but always use it for tabular data. It's sematically incorrect to represent tabular data without using tables.

#10: Someone on 07/22 at 05:54 AM

CSS Forums

CSS Forums: latest threads Last Post Info
Looking for CSS freelancers to outsource work to (26) 12/03/2008 06:16 am
By: iohnee
Shared SSL Certificate by hosting company - is that fine? (2) 12/02/2008 11:53 pm
By: OswaldJim
spacing with the UL tag (1) 12/01/2008 11:11 am
By: mortendc
My Website (5) 12/01/2008 08:15 am
By: austenjones
CSS code coloring (4) 11/29/2008 11:32 pm
By: kamal