Form Layouts With CSS

Laying out forms with Cascading Style Sheets (CSS) is a complex topic. In light of many developers doing their first overall CSS layouts they often bail when it comes to laying out forms with CSS and avoiding both tables and line breaks. The code example shows the following:

  1. Well-formed, semantic markup
  2. CSS for layout and presentation
  3. Ensure that the form is both usable (easy to read/use) and presentable
  4. No tables or line breaks

To avoid the line breaks we simply use the CSS “clear” property. This property says: “clear all floated elements to the x side of me”. So for clear: left; means that there should be no floated elements to the left of the element, and I use this in laying out the form.

Here is the CSS, but be sure to check out the full example.

6 Comments

  1. I havent been bothering with tabindex recently, is that something we should all be adding ?

    Ayush Saran on 03.21.08
  2. @Ayush: It’s not something I add personally. If I do want to provide that kind of usability functionality I set the first form element to be the focus on page load with JS.

    Chris Poteet on 03.21.08
  3. Nice post, helps an aspiring CSS guy like me learn the better way to do things.

    Justin Kohnen on 04.10.08
  4. @Justin: Thanks! I’d say you’re past the “aspiring” part tough ;)

    Chris Poteet on 04.11.08
  5. nice use of css but input[type="submit"] doesn’t work in ie6 so in a lot of cases this isn’t practical

    Andy on 08.13.08
  6. @Andy: You’re correct, but I’ve dropped IE6 support. I’m fed up of being fed up.

    Chris Poteet on 08.13.08

Got Something to Say?

(Required)
(Required)