Open In App

Less.js Color Channel hsvsaturation() Function

Last Updated : 26 Sep, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. This dynamic style sheet language gives CSS more functionality. LESS provides interoperability across browsers. A programming language called CSS pre-processor is used to enhance and compile CSS so that web browsers may use it. It is also a CSS language extension that provides features like variables, functions, mixins, and operations that let us create dynamic CSS while yet keeping backward compatibility.

Less.js Color Channel hsvsaturation() function is used to extract the saturation value of the color object in the HSV color space. It returns a percentage value.  It takes values in hex codes, RGB values, HSL values, and HSV values.

Syntax:

hsvsaturation(value);

 

Parameters:

  • value: This is the parameter that is compulsory for the hsvsaturation() function. It takes values in hex codes, RGB values, HSL values, and HSV values.

Compile LESS code into CSS code.

Example 1: The code below demonstrates the usage and implementation of the Color Channel hsvsaturation() function.

index.html




<!DOCTYPE html>
<html>
  
<head>
    <link rel="stylesheet" type="text/css" 
          href="style.css"/>
</head>
  
<body>
    <h1 style="color:green">GeeksforGeeks</h1
    <h3><b>Less.js Color Channel 
      hsvsaturation() Function</b></h3>
    <div class="container">
    </div>
</body>
  
</html>


styles.less




@body-bg-color: #eeeeee;
@text-color: rgb(0, 200, 100);
@container-bg: rgb(220, 43, 55);
  
body {
    background: @body-bg-color;
}
  
.container{
    height:100px;    
    width:hsvsaturation(rgb(77, 168, 54));  
    padding: 30px 0px 0px 25px;  
    background-color: (#1ed4b9);  
    color:yellow;  
}


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




body {
    background: #eeeeee;
}
.container {
    height: 100px;
    width: 67.85714286%;
    padding: 30px 0px 0px 25px;
    background-color: #1ed4b9;
    color: yellow;
}


Output:

 

Example 2: The code below demonstrates the usage and implementation of the Color Channel hsvsaturation() function with the if and boolean logical functions.

index.html




<!DOCTYPE html>
<html>
  
<head>
    <link rel="stylesheet" type="text/css" 
          href="style.css"/>
</head>
  
<body>
    <h1 style="color:green">GeeksforGeeks</h1
    <h3><b>Less.js Color Channel 
      hsvsaturation() Function</b></h3>
    <div class="container">
    </div>
</body>
  
</html>


styles.less




@body-bg-color: #eeeeee;
@text-color: rgb(80, 188, 134);
@container-bg: rgb(255, 178, 24);
@cond1: boolean(hsvsaturation(@text-color) > 50%);
  
body 
{
   background: @body-bg-color;
}
  
.container
{
   height:100px;    
   width: hsvsaturation(rgb(100, 157, 86));  
   padding: 30px 0px 0px 25px;  
   background-color: if(@cond1, @container-bg, @text-color);  
   color:yellow;  
}


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




body {
    background: #eeeeee;
}
.container {
    height: 100px;
    width: 45.22292994%;
    padding: 30px 0px 0px 25px;
    background-color: #ffb218;
    color: yellow;
}


Output:

 

Reference: https://lesscss.org/functions/#color-channel-hsvsaturation 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads