Like many web designers, I like the ease and the simplicity of CSS and have been very much of the thought; “if it ain’t broke, don’t go making it complicated”.
That is until recently where I’ve found myself repeatedly writing 5 lots of vendor prefixes for something like CSS3′s rounded corners… so I decided to experiment with LESS - a ‘dynamic stylesheet language’ that extends the capabilities of regular CSS to allow for sorely missed features such as variables, mixins, nested rules as well as functions and operations.
There are a couple of options on how to allow LESS to extend your CSS, but the best option I’ve found so far is using the Crunch app, which runs as stand-alone software on your computer (no server-side messing) and outputs your LESS into regular CSS as well as minimising it (to a degree) stripping out all your comments and superfluous line-breaks.
The most beneficial feature of LESS and one of the many reasons why I would be reluctant to go back to writing regular CSS, is that it allows for the fiddliest parts of CSS3 features to be wielded quickly and easily, potentially boosting your website’s awesomeness no end.
For example, for something as simple as a CSS transition, in standard CSS you would have to write out something like this:
Regular CSS3 transition:
div:hover {
transition: all 2s ease-in-out; /* Standard */
-moz-transition: all 2s ease-in-out; /* Firefox 4 */
-webkit-transition: all 2s ease-in-out; /* Safari and Chrome */
-o-transition: all 2s ease-in-out; /* Opera */
-ms-transition: all 2s ease-in-out; /* IE */
}
CSS3 Transition with LESS:
From LESS mixin file:
.transition(@type: all, @duration: 0.3s, @ease: ease-in-out) {
transition: @type @duration @ease; /* Standard */
-moz-transition: @type @duration @ease; /* Firefox 4 */
-webkit-transition: @type @duration @ease; /* Safari and Chrome */
-o-transition: @type @duration @ease; /* Opera */
-ms-transition: @type @duration @ease; /* IE */
}
Now my transition becomes:
div:hover {
.transition(all, 0.5s, ease-out);
}
Which outputs into CSS as:
div:hover {
transition: all 0.5s ease-out; /* Standard */
-moz-transition: all 0.5s ease-out; /* Firefox 4 */
-webkit-transition: all 0.5s ease-out; /* Safari and Chrome */
-o-transition: all 0.5s ease-out; /* Opera */
-ms-transition: all 0.5s ease-out; /* IE */
}
The beauty is you can quickly and easily call all vendor prefixes for the specific CSS3 transition as well as feeding it different parameters by simply writing a short line of code instead of maybe 8.
This is just the tip of the iceberg with regards to have much time and power LESS lends to CSS – I strongly urge everyone to have a play.



Just read in .Net Mag that the W3C have published a draft for CSS to include variables. ‘CSS Variables Module Level 1′. http://w3c-test.org/csswg/css-variables/
Just read in .Net Mag that the W3C have published a draft for CSS to include variables.
ALSO! I’ve just ran into some compiling errors which were caused by CrunchApp running less-1.2.1.js – this has been corrected in their latest CrunchApp update (1.1.2) on github
I love to use http://leaverou.github.com/prefixfree/ so I don’t need to write all vendor prefixes. They’re applied automatically by the script when they’re needed and it keeps my CSS code maintainable and nice looking.
Thanks Johannes! I’ll check that out.