123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Web-Design >> View Article

Stylish And Accessible Web Site Forms In Css

Profile Picture
By Author: Sam Hickson
Total Articles: 3764
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

The majority of sites designed these days have at least one form. If you are a web designer then you will know that creating a template is essential if you are to be efficient in your work.

Many times I have compromised on a forms design due to time restrictions. Below is a template that I use and that is quite flexible in its design. This form allows for any type of input field from a simple textfield to a group of radio buttons. If your quite comfortable with CSS then please feel free to adapt this code.

The fun you can have with this form can really change the way your forms look and make a great deal of difference to your overall web site design.

XHTML CODE

Below is a basic form structure.
I have used ordered lists [ol] to segment the form and [li] tags for each row of the form just as I find this easily breaks up the code for use by novice CSS users.

[form name="cssform" method="post" action="" class="cssform" ]
[fieldset]
[legend][img src="images/personal.gif" /][/legend]
[ol]
[li]
[label for="surname"][em]*[/em] Surname: ...
... [/label]
[input type="text" name="surname" class="newfield" size="35" /]
[/li]
[li]
[label for="forename"][em]*[/em] Forename: [/label]
[input type="text" name="forename" class="newfield" size="35" /]
[/li]
[li]
[label for="company"] Company: [/label]
[input type="text" name="company" class="newfield" size="35" /]
[/li]
[li]
[label for="pCode"][em]*[/em] Post Code: [/label]
[input type="text" name="pCode" class="newfield" size="10" /]
[/li]
[/fieldset]
[fieldset]
[legend][img src=" images/details.gif" /][/legend]
[ol]
[li]
[fieldset]
[legend]Gender [em]*[/em][/legend]
[label][input name="gender" type="radio" /]Male[/label][br /]
[label][input name="gender" type="radio" /] Female [/label]
[/fieldset]
[/li]
[li]
[fieldset]
[legend]Additional information[/legend]
[textarea name="info" cols="32" rows="5"][/textarea]
[/fieldset]
[/li]
[/ol]
[/fieldset]
[div align="center"]
[input type="submit" name="submit" class="submitbutton" value="SUBMIT INFO" /]
[/div]
[/form]

Additional Tags

If you look through the code you will see some tags which you may deem as unnecessary (i.e [br /] tags after the radio button). These are to enable a cross browser compatible layout. Within the CSS code you will notice at the beginning that all the margins and padding are set to zero.

Alternatively you could place the form in a div with zero margins and padding but it is entirely up to you.

CSS Code

* [
margin: 0;
padding: 0;
]
form.cssform [
width: 430px;
font-size: 0.8em;
line-height: 20px;
font-family: Tahoma, Verdana;
]
fieldset [
margin-bottom: 10px;
border: none;
]
label [
line-height: 1.8;
vertical-align: top;
float: left;
text-align: right;
margin-right: 1em;
width: 120px;
font-weight: bold;
]
fieldset ol, li [
margin: 0px;
padding: 5px;
list-style: none;
]
fieldset fieldset [
border: none;
margin: 3px 0 0;
]
fieldset fieldset legend [
padding: 0 0 5px;
color: #000000;
]
legend [
padding: 0 10px 0 10px;
font-weight: bold;
]
fieldset fieldset label [
font-weight: normal;
width: 170px;
margin-left: 123px;
text-align: left;
]
form em [
font-style: normal;
font-weight: bold;
color: #FF0000;
]
input.newfield [
background: url(../images/newfield.gif) repeat-x 0 100%;
border: none;
font-weight: bold;
]
textarea [
float: left;
background: none;
border: 1px solid #999999;
width: 100%;
font-weight: bold;
font-size: 1em;
]
.submitbutton [
width: 10em;
height: 1.6em;
font-weight: bold;
color: #FFFFFF;
background-color: #99ccff;
background-position: center;
]

Browser Compatibility

Currently this form has been tested and works in IE5.5, IE6.0 and IE7 and Firefox.

PLEASE NOTE: for article purposes some of the code tags have been change to a "[" or a "]" so these will need to be adapted for your own use back into the correct syntax

Total Views: 141Word Count: 744See All articles From Author

Add Comment

Web Design Articles

1. How Custom Web Development Can Drive Digital Growth For Modern Businesses In 2026
Author: eleorextechnologies

2. Professional Web Design Services In Rourkela And Sambalpur
Author: Ethan Davis

3. Transform Your Online Presence With The Leading Web Design Companies In Keonjhar And Puri
Author: Ethan Davis

4. Transform Your Online Presence With The Leading Web Design Companies In Dhenkanal And Jagatsinghpur
Author: Ethan Davis

5. Transform Your Online Presence With The Best Web Design Companies In Brahmapur And Cuttack
Author: Ethan Davis

6. Elevate Your Online Presence With A Professional Web Design Company In Baripada And Bhadrak
Author: Ethan Davis

7. Boost Your Online Presence With A Leading Seo Company In India
Author: Ethan Davis

8. Unlock Your Business Potential With Top Seo Services In India And Expert Web Design Company Balasore
Author: Ethan Davis

9. Boost Your Online Presence With The Best Digital Marketing Services In Bhubaneswar
Author: Ethan Davis

10. Leading The Future: Why Choosing The Right Digital Marketing Company In Sambalpur Matters In 2025
Author: Ethan Davis

11. Top Digital Marketing Solutions In Odisha: Why Businesses Prefer Puri And Rourkela Agencies
Author: Ethan Davis

12. Website Design Services In Pune: Crafting Engaging And User-centric Websites
Author: digitaldoraemon

13. Ensure Access To Current Tech With Website Design
Author: Liam Mackie

14. Bootstrap Front-end Development & Ui Framework Services
Author: brainbell10

15. Branding Design Companies
Author: brainbell10

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: