Navigation
Poll
Would you be an active poster if Ron's Guide had a message board?


Total Votes: 62
Comments: 18 — View
Past pollsPoll idea?
Rate Ron's Guide
Rate our resource at Bigwebmaster.com
Custom Input Fields
Learn how to customize the look of your webpage's form fields using cascading style sheets.

You have probably seen many websites on the internet with customized text boxes, select boxes, submit buttons, etc. This tutorial will explain how to achieve the same result using simple CSS codes.

If you have not already read the Introduction to CSS tutorial, I would suggest you do so before continuing.

Alrighty, as you know, CSS uses various selectors to determine how different objects in an HTML document are displayed. To customize our form fields, all we have to do is call upon these selectors and modify the properties we want.

Below is a list of some of the selectors that we can use to modify form fields. Although, in this tutorial we will only need the input, select, and textarea selectors.

  • form
  • input
  • select
  • option
  • textarea

Using each of these selectors you can modify things like the background color, font color, font size, etc. For example, if I wanted to make the text of all of my input boxes use the font verdana with a size of 10px and blue text, I could do this:

<style type="text/css">
input {
    font-family: verdana;
    font-size: 10px;
    color: #0000FF;
}
</style>

That would be fine for changing the font, but what about the background and the border? Simple! All we have to do is add those properties inside the curly braces.

<style type="text/css">
input {
    background-color: #AAAAAA;
    background-image: url('http://mysite.com/input.gif');
    border: 1px solid #555555;

    font-family: verdana;
    font-size: 10px;
    color: #0000FF;
}
</style>

The above would modify all of my input fields to have a gray background with a darker gray border and it would use the background image located at http://mysite.com/input.gif.

The code above, however, would not modify the appearance of the textareas or select boxes on the page. This is because these input fields are created in HTML using a different tag, the textarea and the select tag.

To modify their appearance aswell, all we have to do is add textarea and select to our selectors. You can list as many selectors as you want to take on the properties within the curly braces, just separate each one with a comma.

<style type="text/css">
input, textarea, select {
    background-color: #AAAAAA;
    background-image: url('http://mysite.com/input.gif');
    border: 1px solid #555555;
    font-family: verdana;
    font-size: 10px;
    color: #0000FF;
}
</style>

If you went ahead and used the exact code above, you would end up with form fields that look like this:

Sample form
Input box:
Select box:
Textarea:

Of course, you can always modify the code to your liking. You can modify other properties of each field to further customize your webpages, but that's basically it for modifing form fields.

I hope this tutorial has been helpful. If you have any questions, feel free to post them below.

Discuss Tutorial: Custom Input Fields 1 Comment
Comment by Ferimer5 on Jul 25, 2006, 11:04 pm
BODY { font-family: Verdana, Tahoma, Arial, sans-serif; font-size:

It's also good to have multipul text choixes as some users broswer may not support all.

« Previous [ 1 ] Next »
Post a comment
Sorry, you must be a registered member to post comments.

If you would like to register, you can do so here.
If you already have an account, please login.