Less.js Color Operation shade() Function
Last Updated :
26 Apr, 2025
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Since CSS uses a dynamic style sheet language, it is superior. LESS is adaptable enough to function in a variety of browsers. Web browsers can only use CSS if it is built and developed using a computer language called the CSS pre-processor. While keeping backward compatibility and providing capabilities like variables, functions, mixins, and operations, it helps with the development of dynamic CSS. It is a development in the CSS language.
In this article, we are going to discuss the Color Operation shade() function in Less.js, along with knowing their basic implementation through the illustration.
The shade() function is used to mix a color with black in different proportions and produce a darker shade of the given color. So it is simply the mix() function but the first color is fixed which is black. The third parameter which is the amount denotes the proportion of the black, i.e., 50% means both are in equal proportions. So this function takes the hex value, RGB value, HSL, or HSV value and it returns a value.
Syntax:
shade(color, weight)
Parameter values:
- color: This is the first parameter and it is compulsory and it is the color that will be mixed with black. It can be a hex value, RGB value, HSL, or HSV value.
- weight: This parameter is also compulsory and it signifies the proportion of black in the mixture. This parameter takes a value from 0-100% range.
Refer to how-to pre-compile LESS into CSS article for a detailed description.
Example 1: The below code example demonstrates the usage and implementation of the Color Operation shade() function in Less.js.
HTML
<!DOCTYPE html>
< html >
< head >
< link rel = "stylesheet" type = "text/css"
href = "style.css" />
</ head >
< body >
< h1 style = "color:green" >GeeksforGeeks</ h1 >
< h3 >Less.js Color Operation shade() Function</ h3 >
< div class = "c1" >
< p >shade(rgb(0, 255, 195), 65%)
< br >(Tinted Result)< br >#005944</ p >
</ div >
</ body >
</ html >
|
style.less:
CSS
@body-bg- color : #eeeeee ;
body {
background-color : @body-bg-color;
}
.c 1 {
width : 350px ;
height : 150px ;
margin : 1 rem;
background-color : shade( rgb ( 0 , 255 , 195 ), 65% );
}
p {
padding : 40px 0px 0px 20px ;
color : #ffffff ;
}
|
Now, to compile the above LESS code to CSS code, run the following command:
lessc style.less style.css
The compiled CSS file comes to be:
style.css:
CSS
body {
background-color : #eeeeee ;
}
.c 1 {
width : 350px ;
height : 150px ;
margin : 1 rem;
background-color : #005944 ;
}
p {
padding : 40px 0px 0px 20px ;
color : #ffffff ;
}
|
Output:
Example 2: The below code example demonstrates the usage and implementation of the Color Operation shade() function with the if() and boolean logical functions and the color type function.
HTML
<!DOCTYPE html>
< html >
< head >
< link rel = "stylesheet" type = "text/css"
href = "style.css" />
</ head >
< body >
< h1 style = "color:green" >GeeksforGeeks</ h1 >
< h3 >Less.js Color Operation shade() Function</ h3 >
< div class = "c1" >
< p >shade(#ff0000, 70%)
< br >(Tinted Result)< br >#4d0000</ p >
</ div >
</ body >
</ html >
|
styles.less:
CSS
@body-bg- color : #eeeeee ;
@ color : hsl( 177 , 100% , 39% );
@second: rgb ( 58 , 21 , 11 );
@hex: shade( #ff0000 , 70% );
@cond: boolean(iscolor(@hex));
body {
background-color : @body-bg-color;
}
.c 1 {
width : 250px ;
height : 150px ;
margin : 1 rem;
background-color : if(@cond, @hex, @color);
}
p {
padding : 40px 0px 0px 15px ;
color : if(@cond, @color, @second);
}
|
Now, to compile the above LESS code to CSS code, run the following command:
lessc styles.less styles.css
The compiled CSS file comes to be:
style.css:
CSS
body {
background-color : #eeeeee ;
}
.c 1 {
width : 250px ;
height : 150px ;
margin : 1 rem;
background-color : #4d0000 ;
}
p {
padding : 40px 0px 0px 15px ;
color : hsl( 177 , 100% , 39% );
}
|
Output:
Reference: https://lesscss.org/functions/#color-operations-shade
Similar Reads
Less.js Color Operation spin() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. CSS is better since it makes use of a dynamic style sheet language. LESS is flexible enough to work in a wide range of browsers. CSS is created and improved using
3 min read
Less.js Color Operation saturate() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Because it uses a dynamic style sheet language, CSS is more useful. LESS is adaptable enough to function in a variety of browsers. In order for web browsers to use
3 min read
Less.js Color Operation Functions
Less (Leaner Style Sheets) is an extension to normal CSS which basically enhances the abilities of normal CSS and gives it superpowers. Color operation functions are built in Less.js to perform various operations such as saturation, de-saturation, lighten, darken, etc on a color object and return th
8 min read
Less.js Color Operation tint() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. CSS is better since it makes use of a dynamic style sheet language. LESS is flexible enough to work in a wide range of browsers. CSS must be created and developed
3 min read
Less.js Color Operation mix() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Since CSS uses a dynamic style sheet language, it is superior. LESS is adaptable enough to function in a variety of browsers. In order for web browsers to use CSS,
4 min read
Less.js Color Operation fade() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Because CSS uses a dynamic style sheet language, it is more advantageous. LESS is adaptable enough to function in a variety of browsers. A computer language called
3 min read
Less.js Color Operation darken() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. It is more advantageous because CSS employs a dynamic style sheet language. Several different browsers can use LESS because of its flexibility. In order for web br
3 min read
Less.js Color Operation fadein() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. It is better since CSS makes use of a dynamic style sheet language. LESS is flexible enough to work in a wide range of browsers. To create and improve CSS so that
3 min read
Less.js Color Operation lighten() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Because CSS uses a dynamic style sheet language, it is more advantageous. LESS is adaptable enough to function in a variety of browsers. A computer language called
3 min read
Less.js Color Operation fadeout() Function
Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Since CSS uses a dynamic style sheet language, it is superior. LESS is adaptable enough to function in a variety of browsers. A computer language called the CSS pr
3 min read