Monday, October 21, 2013

How I Format My CSS Files

I've read about a dozen articles on CSS file formatting and management. I must say, I don't agree completely with any of them. Not to say that the way they do things is "wrong", but I don't subscribe to their way of CSS file formatting. Here's how I do it.

One-Line Selectors & Attributes


I like placing selectors and their attributes on one line. It helps me avoid endless scrolling in my CSS file. Many would argue that this makes reading the CSS difficult, but I actually find it to be easier. This also reduces the size of the CSS file.

Tabify Nested Classes

Tabifying (indenting) classes below the others is essential to CSS file readability and structure organization.

All Medias in One File

Adding the media declarations to the CSS file allows me to place all of the CSS in one file instead of switching between buffers to update files.

Globals, Structure, Tags, Custom Classes, Links

I always organize the selectors in the following orders: globals, structure, tags, custom classes, and links. This, in my opinion, outlines the importance of each group of selectors.

21 Ticks

I try to start all braces at the 21 character mark. This number isn't necessarily meaningful -- I could indent as far out as I want.

Your Thoughts?

What do you think of this system? Have any suggestions?