Stop writing CSS

Thu 07 January 2010 | -- (permalink)

And write LESS instead. LESS code is basically CSS with variables and some other sugar on top, that compiles down to vanilla CSS when you run it through the "lessc" program.

There are other programs out there that do this (I briefly considered the python-based CleverCSS), but the thing I like about LESS is that all valid CSS is also valid LESS. So you can take your existing CSS file, rename it to 'mystyle.less' and run it through the preprocessor just to get margins and whitespace and the like cleaned up nicely.

Once you've done that, you can start incrementally fixing up your .less file; replacing repeated references to the same color with one variable name, for example. You can nest CSS rules so that things that go together are naturally grouped together (and are much more readable too).

There's more, but I haven't gotten there yet. I've been playing with it for all of 30 minutes, and already had a few spells of gleeful geeky cackling at how much nicer it makes CSS.