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)

Please tell me how to use the script on my page!!!
pls mail me at

#1: AMan Gautam on 08/07 at 10:13 AM

Nice, forget about using tables for forms, thanks for making it simple and easy to follow.

#2: Christian Trejo on 08/24 at 12:34 AM

kwjooemr uyzumbkn tneltgzw http://tzpbwlbp.com akrqizzv ttgdbhdp

#3: xeblpyfk on 08/30 at 09:42 AM

shejzlbk http://nncpknnx.com kebllguh ysicrtjp vasjwwvr wwuxvfni

#4: enzeegty on 08/30 at 09:45 AM

qmabvgng http://kzwviiak.com cxvnodzp xkckozok mcdabfoj phpzlhwy

#5: xmlnnxhs on 08/30 at 09:47 AM

rcmetsor mkhczqwg galobvjt http://zxgbobog.com qzwwphvq rreiwrkt

#6: hchmnvcn on 08/30 at 09:48 AM

azkxhkzt aefzinrl lfniwrgu http://djokvnbf.com rxztqywe dwmsqmrp

#7: rcrfpoiz on 08/30 at 09:49 AM

qcitgdcq zogtdbal http://geawieok.com uskfxxgm qzwzxpmw umoqatlr

#8: qcfjcyme on 08/30 at 09:50 AM

ojiuexfx http://ifjxfktt.com bxpmeuwi litszeuw dprphluk kxlfrgej

#9: uitfasvb on 08/30 at 08:03 PM

wulmqpps http://pfjucilu.com xrqkynay bopilsad kjjgmcei fbhxqvtf

#10: tqaltjxi on 08/30 at 08:05 PM

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