8 tips for “scaling” CSS Development
Effective development of any project (whether web or otherwise) requires effectively “scaling” the code-base. The experienced shops like Amazon break their code into services - modular components that are easy to understand and maintain by a small group of developers. I don’t need to hark on the benefits of modularity, but one can never overstate the importance of having a “shallow” code-base. The best software architects know this, and the big shops apply these techniques effectively.
However, from my observations, CSS always tends to get left out of good code-base architecting. That’s probably because designers who work with CSS only do it as a means to and ends - getting a pretty and usable design, while developers who work with CSS couldn’t run away from it fast enough. It’s stuck in some void where people approach it with a 10-foot pole.
Oddly enough, it’s CSS that is often in most need of solid architecting. After all, the “language” (if you can call it that) sucks, was poorly designed, doesn’t work consistently in most browsers, isn’t DRY, and makes people want to take a sip of the old table driven kool-aid once in a while.
Here’s how I approach the problem:
- Break your CSS files down. Give your CSS files short, easy to understand names. “basic.css” is not a good name. What’s basic about it, exactly? “main.css” is a poor name. Is it the main CSS file or CSS for the page called main? I like to use “common.css” for CSS patterns (more on that later), “style.css” for styling only (more on that later) and “x.css” for pages called x.
- Use an asset manager. This goes with number 1. Breaking your CSS down into small chunks means more round-trips if you <link> each stylesheet. Go with an assest manager to bundle all those files for you. For example, try bundle-fu for Rails.
- Separate styling and layout. Styling is what your <em>s <strong>s <h1>s look like. Layout is probably specific to the page. Get detailed. “styling.css” can be for basic HTML elements, “styling-modules.css” can be for styling specific to reusable modules, etc. Developers call it separation of concerns. CSS designers call it sanity.
- Don’t put IE specific hacks into their own file. (Only do this if you don’t care about validation.) This flies in the face of convention wisdom. Well, the next time you’re wonder why something looks different in IE after pouring through your CSS, only to realize 30 minutes later that something’s inconsistent in “ie6.css”, don’t forget what I told you here. IE specific CSS files are un-DRY. Instead, put the hacks as close to the non-hacked CSS as possible and document it.
- Use common patterns. People spent countless hours on things like clearfix and the holy-grail so you don’t have to. Put these common patterns into their own file (I like common.css and common-layout.css) and don’t mess with that file.
- Use a reset. This is an extension of #5. Resets means your CSS works tabula rasa. No more wrestling with inconsistent browser defaults. Try these reset rules. Make sure you document any exclusions for bandwidth saving reasons.
- Use white-space effectively in CSS files. This one doesn’t work for me, but I’ve seen people swear by it. Use indentation to mimic the DOM hierarchy when you’re doing complex selectors.
- Document CSS like you would document code. And realize that sometimes the best documentation comes from having well thought out CSS in the first place, just like how good code documents itself. If you’re working in an environment where many people are touching the same CSS files, having everyone understand the organization (see #1) is the only documentation you’ll need.
I’m sure there’re are more best-practice approaches to “scaling” CSS so that more than one person can work on it without going bananas, but these work well for me. Heck Ronin only uses a subset of these rules, and it’s already saving me my sanity. Google around and maybe you’ll find more to add to this list.

Useful information.
Also, following a naming convention for class names, element IDs will also help.
Veera
22 Sep 08 at 3:01 am
I think using a hundred different css files (ex layout.css, contact.css) is pointless unless you’re using a framework. It just makes things harder to find. And if you’re using some sort of versioning system, it shouldn’t be a big deal to make and track changes. Just my opinion.
Fred
22 Sep 08 at 3:58 pm
I’d add that you shouldn’t be afraid to compartmentalize into several different files — combination and minimization are optimization techniques, but they needn’t affect your workflow (of having multiple files for development).
Marcus Cavanaugh
22 Sep 08 at 5:50 pm
@fred: Use folders as part of your file structure just like you would any part of your source code. Also, nothing sucks more than being on revision #568 (a real number I’ve seen) because everything is thrown into one huge CSS file.
Lu Wang
22 Sep 08 at 6:13 pm
“Don’t put IE specific hacks into their own file.” is a bad recommendation and is more costly to maintain. Consider if/when the IE styles become obsolete; by mixing these up with the core CSS file, you would have to go and weed them out when the time comes. The extra IE stylesheet on the other hand can be simply unlinked.
The difficulty you are are facing has to do with CSS specificity. Once you are comfortable with it, you know exactly which style from which stylesheet gets applied.
At the end of the day the styles only for IE is fairly minimal. This is hardly an issue nowdays.
Sarven Capadisli
23 Sep 08 at 2:35 pm
Unlike Sarven, I think Rule #4 is very important and often overlooked because of its lack of purity. If you’re building an extremely complex web application, having IE specific declarations below their standards-based declarations is extremely important from a maintenance standpoint. I don’t advocate the use of “hacks” however, but I do encourage IE specific CSS selectors. You can create these by using conditional comments around a wrapper div just inside the body tag.
NICCAI
25 Sep 08 at 7:00 am
@NICCAI: Precisely.
When you’re dealing with CSS development that truly scales (more than 1 or 2 developers), you need to have the maintenance ease. I think some readers might be forgetting that this article is not about design specific CSS. This is about CSS in the wild where who-knows-what is changing with large CSS code-bases.
IE specific selectors is a new one on me - I’ve never been fond of altering the DOM for CSS needs. I’m not quite sure how I feel about that one.
Lu Wang
26 Sep 08 at 4:28 am