HOW TO STYLE A HTML FORM WITH CSS AND NO EXTRA MARKUP

If you haven’t read it yet then I strongly recommend that you take a look at Cameron Adams article Fancy Form Design Using CSS if you are really serious about tackling this aspect of web design.

It’s an extremely well-informed piece that offers a myriad of tips including cross-browser compatibility details and usability and accessible markup advice.

However, one aspect of Cameron’s article that I didn’t like was the use of an ordered list. I really hate to add extra code unless it is absolutely necessary and, lets face it, styling a form by using a list is just a hack.

How to style a HTML form with CSS and no extra markup is amazingly simple really. This is what the code looks like:

input,
select{
display : block;
}
label {
float : left;
width : 200px;
}

And that’s it. It produces a form like in the image below with no extra HTML coding such as an ordered lists or line breaks. It works across all browsers including Internet Explorer.

The above code is just the foundation for form design and reading Cameron Adams article will give you lots more ideas about how to get it right.

Leave a Reply

Your email address will not be published. Required fields are marked *