Open In App

How Less is similar to Sass ?

Last Updated : 06 Dec, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

CSS preprocessors are programming languages that extends all the features of CSS but it helps to reduce the code complexities of CSS using different features like mixins, variables, and many other features that make the code clean and easy to understand. These languages require the compiler to compile the code back to normal CSS.

Currently, the two most used CSS preprocessors are SASS and LESS. Though both of them are quite different they have some similar concepts. In this article, we will discuss the similarities between LESS and SASS.

The aspect in which both SASS and LESS are similar to each other are mentioned below:

  1. They both are CSS preprocessors
  2. Concept of Variables
  3. Concept of mixins
  4. Concept of Nesting
  5. Concept of Importing

Now, let us discuss the points one by one in detail.

1. CSS Preprocessors: As we have stated earlier both SASS and LESS are CSS preprocessors so both of them require some special compiler to compile them into regular CSS files which can be directly linked to the HTML file.

2. Variables: Variable is a very useful element that is found in many popular languages like Python, Java, and so on. This feature is not available in regular CSS but in both LESS and SASS we can assign variables to store any CSS value to be used multiple times. The only difference here is that the syntax is different.

Given below are the syntaxes to define a variable in both languages:

Syntax: Defining a variable in LESS

@color_variable: red;

Syntax: Defining a variable in SASS

$color_variable: red;

3. Mixins: Mixins are just like a function that contains a bunch of CSS properties that can be used anywhere in the code. They have parameters that we can pass with different values while calling for different elements. Both LESS and SASS support the feature of Mixins.

Given below are the syntaxes to define mixins in both languages:

Syntax: Defining a variable in LESS and using it in another class

.button_mixin {
    color: blue;
    border: 2px solid black;
    padding: 1em;
}

.container {
    height: 100px;
    .button_mixin;
}

Syntax: Defining a variable in SASS and using it in another class

@mixin button_mixin
    color: blue
    border: 2px solid black
    padding: 1em

container
    @include button_mixin
    height: 100px

4. Nesting: Nesting is a very important concept of programming languages. In nesting, we can write one block of code inside another block. Both SASS and LESS support nesting but their syntax is different.

Given below are syntaxes showing the nesting feature both in LESS and SASS:

Syntax: Defining a variable in LESS

nav {
    ul {
        margin: 0;
        padding: 0;
    }
    li {
        display: inline-block;
    }
    a {
        display: block;
        text-decoration: none;
    }
}

Syntax: Defining a variable in SASS

nav
  ul
    margin: 0
    padding: 0

  li
    display: inline-block

  a
    display: block
    text-decoration: none

5. Importing: Importing in CSS preprocessors is a feature in which we can import a complete file of either SASS or LESS to another one completely including all the mixins, variables and other code. This feature gives a modular approach to the code while designing a large website where writing on a single file can make the code length very long to read and navigate for making any corrections and changes. 

Using the importing feature, we can write different sections of the code in different files and finally import them to one main SASS or LESS file. This feature of importing is present both with SASS and LESS and we can use these to make our code cleaner.

Given below are the importing syntaxes for both languages:

Syntax: Defining a variable in LESS

@import "sample1.less"
@import "sample2.less"

Syntax: Defining a variable in SASS

@import "sample"
@import "sample2"

Thus, from the above points, we got a detailed overview of the similarities between the LESS and SASS. They also have some additional features above each other. In recent times, both of them are very much in use by the developers and both are having some pros and cons of their own. The choice basically depends on the developer’s own choice rather than need as both of them almost does the same work but in a slightly different manner.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads