DEV Community

Cover image for Sass and Less: What's the Difference Between Both?
Shariq Ahmed
Shariq Ahmed

Posted on • Updated on • Originally published at Medium

Sass and Less: What's the Difference Between Both?

In CSS, you can't use features including variables, imports, built-in functions, nested rules, and mixins. You need to use any CSS preprocessors. Fortunately, there is something that you can use to avail all these features: Sass.

Using Sass, your CSS will be more organized and easier to maintain. You can also create complex styles easily.

But wait. What is actually a preprocessor? Well, it's a scripting language that is compiled into a regular program. In simple words, a preprocessor inputs data to give output that is further used as input in another program.

However, the thing is, the browser can't comprehend Sass code. You must use a Sass pre-processor that can convert Sass code into CSS. This whole process is also called transpiling. Another benefit of using Sass is that its variable helps you reuse the styling. Moreover in Sass, you can store information in variables like

  1. Strings
  2. Numbers
  3. Colors
  4. Lists
  5. Booleans
  6. Nulls

And all these variables must be used with $ in Sass. The scope of these variables, on the other hand, is valid at the nesting level where they are defined. Further, Sass allows you to nest CSS selectors which makes the work really efficient because then you don't have to repeat outer selectors repeatedly. You just need to write nested selectors in order and Sass will combine the work automatically.

Apart from Sass, there is another CSS preprocessor called Leaner Style Sheets(Less). It's a scripting language as well as a backward-compatible language extension for CSS. But contrary to Sass, variables of Less are also initialized with @. But the thing is in Less, there are fewer frameworks as compared to Sass.

But between Less and Sass, what should you use? In fact, what's the difference between these two? Well, the main difference is that Sass is coded in Ruby. Whereas, Less is written in JavaScript. Further, Sass uses $ for variables, and @ is used in less. The software support of Less is also a bit fragmented as compared to Sass.

But, still, I would prefer Less over Sass because it tells you the correct location of the error. The same isn't true for Sass. It doesn't pinpoint the exact location of the error.

Top comments (0)