VOOZH about

URL: https://www.geeksforgeeks.org/css/css-preprocessor-less/

⇱ CSS Preprocessor LESS - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

CSS Preprocessor LESS

Last Updated : 13 Apr, 2026

LESS (Leaner Style Sheets) is a CSS preprocessor that extends CSS with dynamic behavior, including variables, nesting, mixins, and mathematical operations, all while maintaining compatibility with standard CSS.

  • Variables: Store reusable values like colors, fonts, and measurements using the @ symbol.
  • Mixins: Include reusable groups of CSS properties in other rulesets.
  • Nesting: Write CSS in a hierarchical structure reflecting the HTML.
  • Mathematical Operations: Perform arithmetic on CSS values.
  • Functions: Use built-in functions for math, color manipulation, and more.

Working of LESS

A browser cannot directly process LESS code. A LESS preprocessor compiles the LESS file into standard CSS that browsers can interpret.

Working Steps

  • Write the LESS code in a .less file.
  • Compile the LESS file into CSS using lessc style.less style.css.
  • Link the compiled CSS file in the HTML document.

Here is a list of all the features of LESS, each explained one by one:

1. Variables: Variables can be used to store CSS values that may be reused. They are initialized with @. 

Syntax: To compile the above less code to CSS code write the following command-

lessc style.less style.css

The compiled CSS file comes to be: 


2. Mixins: Mixins are a way of including a bunch of properties from one rule-set into another rule set. 

Syntax: To compile the above less code to CSS code write the following command-

lessc style.less style.css

The compiled CSS file comes to be: 


3. Nesting: LESS gives you the ability to use nesting. 

Syntax: To compile the above less code to CSS code write the following command-

lessc style.less style.css

The compiled CSS file comes to be:


4. Mathematical Operations: Arithmetical operations +, -, *, / can operate on any number, color, or variable. 


Syntax: To compile the above less code to CSS code write the following command-

lessc style.less style.css

The compiled CSS file comes to be:


5. Functions: LESS provides a variety of functions like math, list, string, color operations, color blending, etc.

Syntax: To compile the above less code to CSS code write the following command-

lessc style.less style.css

The compiled CSS file comes to be: 

Example: File name gfg.html

Output:

👁 Functions output

Advantages of LESS

  • LESS is cross-browser compatible.
  • LESS provides a list of operators making it easy for users to code.
  • Maintenance is easy due to the use of variables.

Disadvantages of LESS

  • LESS provides fewer frameworks as compared to SASS.
  • It can be tricky to those who are new to CSS.

Best Practices for Using LESS

  • Modularize Your Code: Divide your styles into logical, reusable modules or partials to enhance maintainability.
  • Limit Nesting Levels: Avoid deep nesting to prevent overly specific selectors and maintain readability.
  • Utilize Variables: Define variables for commonly used values like colors and fonts to ensure consistency and simplify updates.
Comment
Article Tags: