How to import LESS through npm ?

LESS stands for Leaner Style Sheets. It is a backward-compatible language extension for CSS. Web pages can be styled by writing appropriate code in a file with .less extension and then converting it in a CSS file.

Steps to install LESS:
Step 1: To install LESS, first make sure that node and npm are already installed in the system. If not, then install them using the instructions given below.

  • Download the latest version of node in the system and install it.
  • Now open command prompt and move to your project folder.
  • Now you need to create a package.json file to manage the dependencies. To do so, use the command given below.
    npm init

    After which you will be asked for the package name of the user’s choice and the description. For other formalities, just press enter and your package.json file will be created.

Step 2: Now install LESS using the command:

npm install less

Note: Install the LESS npm module globally so that it can be used by any project, use the command npm install less -g. If you are executing this on a Mac or Linux machine, you may need to add “sudo” to the beginning of this command.
Step 3: To compile .less file, use the command:

lessc input.less output.css

Note: Make sure that you run this command in the same folder which contains input.less file. This completes the compilation of the LESS file to CSS file which can now be added to the HTML file.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.