Working often with CSS for my own website or for my job makes me trying always to be organized and that made me thinking about a thing. What is the best way to organize my CSS file(s)? With this article I will try to present you a short guide about CSS organizing.
1.Group your CSS files into a folder
Beside your main CSS file you may want to use also a print CSS file or why not a CSS file for the IE6 browser. Placing them together in a folder named css for example will help you improve your website back-end structure.

2.Use efficient selectors
A very important thing for you to know is how browsers understand and read your CSS selectors? The answer is that they read them from right to left. That means that for the selector ul li a span the first thing thing interpreted is span.

The id is the selector with the greater specificity so always, instead div#header you should use just #header. This way your file will be less redundant and smaller. Also note that the use of efficient CSS selectors is a nowadays requirement.
3.Comment and separe your CSS rules
Generally, a CSS file contains reset styles, header, content and footer styles and in order to easier browse your CSS rules you should choose a way to separe them.

You can choose an simple and easy to notice separator as in the following example:
/* Header styles */ /* ---------------------------------- */ /* Content styles */ /* ---------------------------------- */ /* Footer styles */
4.Create a simple color scheme to use for your styles
When you are dealing for example with a CSS file for an web application you will use a lot common styles and colors. So placing something as following inside a CSS comment could be very helpful for you:
/* Colors: Light Gray #eaeaea, Dark Gray #828282, Red #c60000 */
5.Use a meaning naming convention for your selectors.
Let’s suppose you need to name your logo, menu and a tagline that are placed inside a header id wrapper. A good approach in this way would be to use namings as:
- header-logo or h-logo
- header-menu or h-menu
- header-tag or h-tag

6.Create your own small CSS framework
By doing that you will be able to use these common CSS classes at any time for any elements from your markup.
.full-width
{
width: 100% !important;
}
.min-width
{
width: 1% !important;
white-space: nowrap !important;
}
.centered-inline
{
text-align: center !important;
}
.centered-block
{
margin-left: auto !important;
margin-right: auto !important;
}
7.Simple is better
Don’t try to complicate things because simplicity will save you time, effort and why not your remaining hair :).

Great thanx
awsoume yar thax alot
Thanks for your comments and let me know what other organizing tips you use!
Good!
I always follow theses tips. Thanks!
Felipe, nice to hear you like this. Thanks for your comment!
Hey there! I’m at work browsing your blog from my new iphone 4! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the great work!
Hi! Great tips, though the first one is an outdated approach.
You should rather use just one css file, and add the print stylesheet to the end of the css with “@media print” media query.
For the IE-specific stylesheet, rather just use conditional comments to add ie-version specific classes to the html element, then just create the matching rules in the main css file.
This way you reduce the number of requests to the server, instead of loading 3 css files, you just need one.
This has been well implemented in the HTML5 boilerplate, take a look if you are interested. (http://html5boilerplate.com/)
Aron, I agree with you regarding this matter, thanks for the heads up.
I am now sure that choosing the
print.cssas an extra CSS file for this example wasn’t the best choice. :)I like to split up my css content with includes:
@import url(“base.css”);
edit: with imports.. sorry
Martin, @import seems to be quite bad.
ah, ok. didn’t know that. thanks for the links