A contact form is pretty much a necessity for any website these days, creating one is fairly simple. Making them look good is where the real skill lies. By using some simple Css rules your forms can really rock!
This is what we are aiming to end up with;
Preview
Live Preview
form full
The Mark-up
There are many elements that make up a form, some of which are neglected or seen as not necessary. But its important to include these for Accessibility reasons, lets take a look at a simple contact form.
This will give us a basic form structure, I am not going to explain what each tag does, as this tutorial aim is how to style them.
However if you wish to find out a little more, there is a great explanation on Forms over at W3schools.com
Adding extra markup
As there are many tags within the form there will be many styles that need to be created.
However as many of the tags will be styled the same, it would be easier to group them. That way we can drastically cut down the number of rules within our Css.
How are we going to do this? Simple, we can use our trusty unordered list
- and list tags
- .
First we need to decide what elements we wish to group. The logical answer would be our
and our form, Lets do that. You may have notice that I have used 2 unordered lists, this is so we can style the
Now we need to start adding our Css rules to our unordered list. So what rules are we going to add?
Firstly we will remove the bullets, the indent, and the padding, these are styles set to the element automatically.
We also need to separate our form elements a little better, so they have some room to breath. For this we will add some styling to the
- elements
ul {
list-style: none; /* Removes the Bullets */
list-style-position: inside;
padding:0; /* Aligns with the edge of the Form Field */
}li {
margin:10px 0; /* Adds 10px Margin to the Top + Bottom */
}So that’s our unordered list elements are all sorted, lets take a look at styling some of our
elements. Again by default these already have styles associated with them (width, height, border etc.) so we need to over ride a few.Now because we only want to access the
andli input, textarea { /* Sets Rules for 2 Elements */
height:15px;
padding:5px;
border:1px solid #E8E8E8;
width:288px;
}Lets take a look at what each element is doing;
The Width , Height and Border should be self explanatory, the Padding however, allows us to have the cursor in the center of the
box, it just makes it a little more stylish.Now obviously we need to change some of the rules for our
textarea {
font-family: Arial, sans-serif; /* Changes default font */
font-size: 12px;
height:150px;
}Styling the Buttons
So we have styled the elements for input, now we need to give our buttons a little makeover, these have rules added to them by default so once again we need to over ride them.
Now in order to separate them to the rest of our
rules, we are going to add some classes to them.Now we can reference them both in our Css (you can set the colors to match your site);
.button {
border:1px solid #E8E8E8;
padding:5px 10px;
margin:0 5px 0 0;
cursor: pointer; /* Changes the cursor behavior */
background: #AC0000;
color: #FFFFFF;
}.reset {
border:none;
padding:5px 10px;
margin:0 5px 0 0;
cursor: pointer;
background: #FFFFFF;
color: #AC0000;
}Styling the rest
Right so, we have styled the elements within the form itself, lets go out a little bit and look at our
