Find your next home with Luxist's "Estate of the Day"

Formatting your stylesheets

SixThings has a post about CSS visual grouping techniques. To some, this is something that might not seem very important, since it doesn't affect the user or how the styles are rendered by the browser. However, these under-the-hood details are important, as you well know if you've ever had to work on code that's been touched by other developers.

I utilize many of the techniques mentioned in the article, but there are some that I've personally found to be more confusing than helpful. For example, in my experience, the "simple indentations" method reduces readability.

I would add the following techniques to the SixThings list:
  • List properties alphabetically. I used to group them according to their function or type, as described in the article (e.g., height and width together), but found the alphabetical approach to be what works best for me. This way, I can eyeball any selector and see what's there without overlooking anything, because I know what order to expect.
  • Put lots of whitespace between sections. Okay, obviously "lots" is relative; you don't want to put 10 blank lines between your header styles and your content styles. I usually put 2 lines between sections, and visually demarcate them further with the following type of notation:

    /*  =HEADER
    ------------------------------------------------------- */
What techniques (or "best practices," if you want to break out the biz-speak) do you use to keep your stylesheets organized and readable?

Reader Comments

(Page 1)

RESOURCES

RSS NEWSFEEDS

Powered by Blogsmith

Other Weblogs Inc. Network blogs you might be interested in: