CSS Style Naming Strategies

Jun 5th, 07 | 2 remarks

One of the most important aspects of programming in any language is giving your variables, arrays, etc., meaningful names. The same is true for CSS. Only you can determine what’s meaningful to you, but one tactic is to choose names for your divs and classes that can withstand any number of redesigns.

For example, aside from using names such as #header, #sidebar or #footer to set up the basic framework of your design, try to avoid names like #left_column, #subfooter, or something vague like #secondary_right. The reason is because information appearing in those sections now, may not later.

Instead, select names which are relevant to the content they’re being assigned to, like #main_nav, #copyright, or #rss_info. This way, no matter where you decide to put, say, your navigation (whether it’s in the header or a sidebar), you only have to worry about modifying the actual styles in the CSS, and not the names in the markup. Of course you may still have to shuffle your HTML around some in a redesign, but for the sake of brevity we’re just talking style names.

Granted, this concept may not always be feasible, but the more you can minimize names which are given according to placement within the design rather than content relevancy, the better. If you’re one who likes to redesign/refresh often (like me), then employing a naming strategy which makes sense to you can save you a lot of dev/testing time in the future.


  1. Deaf Musician

    I use #sidebar1, #sidebar2 instead of leftsidebar and rightsidebar. I usually try to name it by describing what the div is instead of generic names, sidebars are exceptional to this rule.


  2. Charity

    I agree sidebars fall into an exception. I mean, they’re sidebars! Hard to get creative in naming them. :) One nice thing about using your suggestion is they could be moved around without renaming, as in 2 left sidebars, or one on each side, etc. I’ll admit though, I quickly forget which is which when I use numbers in my IDs so I usually avoid that naming convention.

Post your remark

Other Recent Articles

In Reviews »

Clever Development With Coda

07/15/08
If you follow design related blogs, it seems you can't click a mouse anymore without Coda's icon making an appearance. I heard about this software long before buying my Mac, but because it's exclusive to that platform, I was never able to give it a test run. Now eight ... [ » ]

In Inspiration »

Have You Ever?

06/25/08
If you know me very well, you know how important music is in my life. It's playing at all times in my house, and I embrace all kinds of genres. I don't talk about it much on this blog, but I should. Music and creativity, in my opinion, are inextricably ... [ » ]

In Design »

The Evolution of a Logo (I Can Live With)

06/19/08
One of the most frustrating things for me since I started writing on this blog was the lack of a logo I really loved. That's not to say I haven't tried. But logo design, to me, is kind of a thing all it's own and I'm just not very good ... [ » ]