By efficient I mean less code (less css rules).
Because I'm converting a CSS file to less, and I'm surprised to find out that the compiled CSS file is quite small (I haven't finished yet :P)
With the freedom and capabilities that comes from using variables, mixins, and functions, CSS preprocessors can keep your stylesheets well-organized, flexible, reusable, and more maintainable to help you write better and cleaner CSS code.
A CSS preprocessor is a program that lets you generate CSS from the preprocessor's own unique syntax. There are many CSS preprocessors to choose from, however most CSS preprocessors will add some features that don't exist in pure CSS, such as mixin, nesting selector, inheritance selector, and so on.
CSS preprocessors make it easy to automate repetitive tasks, reduce the number of errors and code bloat, create reusable code snippets, and ensure backward compatibility. Each CSS preprocessor has its own syntax that they compile into regular CSS so that browsers can render it on the client side.
It really depends how you structure your code in LESS. The compiled output can become quite unwieldy if you use a lot of mixins (for example for gradients) or the @
operator to nest selectors too liberally.
All in all one could argue that they 'can' produce more efficient code if used properly. But then, so can you I you use plain CSS.
LESS (when compiled) and Sass both minify your CSS. In addition to stripping out whitespace, you'll sometimes see things like border: 0 10px 0 10px
get turned into border: 0 10px
or colors like #666666
turned into #666
. It isn't any more efficient, but it does make a smaller download for the user (which is valuable for mobile devices).
That said, Sass has a unique directive called @extend, which allows you to group your styles logically in the pre-compiled state, but will group them together to avoid duplication in the compiled state.
.classA { color: blue }
// 50 lines of code defining other elements...
.classB { @extend .classA }
Will output something that looks like this:
.classA, .classB { color: blue }
It doesn't seem like that big of a deal with 2 classes only having one thing in common, but its a bigger deal the more elements you are using and the more things they have in common.
Otherwise no. The efficiency is entirely based on the author.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With