Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Less.js Color Definition hsl() Function
Next article icon

Less.js Color Definition Functions

Last Updated : 28 Sep, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Less (Leaner Style Sheets) is an extension to normal CSS which basically enhances the abilities of normal CSS and gives it programmatic superpowers. In this article, we are going to see Color Definition functions in Less.js. 

Color definition functions are provided by Less.js, which basically are used to define a color object using properties like red, green, blue, hue, saturation, etc. There are 7 Color Definition functions provided by Less.js which are as follows:

  • rgb: It is used to create an opaque color object (in hex format) by taking decimal red, green, and blue values (RGB) as an argument.
  • rgba: It is used to create a transparent color object (RGBA format) by taking decimal red, green, blue, and alpha values (RGBA) as an argument.
  • argb: It is used to create a hex representation of a color object in #AARRGGBB format (and not in #RRGGBBAA format). 
  • hsl: It is used to create an opaque color object by taking hue, lightness, and saturation (HSL) values as an argument.
  • hsla: It is used to create a transparent color object (RGBA format) by taking hue, saturation, lightness, and alpha (HSLA) values as arguments.
  • hsv: It is used to create an opaque color object (hex format) by taking hue, saturation, and value (HSV) values as arguments.

Note: This color space is available in photoshop and is not the same as HSL.

  • hsva: It is used to create a transparent color object by taking hue, saturation, value, and alpha (HSVA) values as arguments.
 

Example 1: In this example, we have 2 colors, @color1 using hsla() and @color2 using rgb(), and then applied them to the h1 tag and h3 tag respectively.

HTML
<!DOCTYPE html> <html lang="en"> <head>     <title>Color Definition Functions in Less.js</title>     <link rel="stylesheet"            href="styles.css"> </head> <body>     <h1>GeeksforGeeks</h1>     <h3>Color Definition Functions in Less.js</h3> </body> </html> 

styles.less: The LESS code is as follows:

styles.less
@color1: hsla(150, 100%, 50%, 0.3); @color2: rgb(255, 127, 80);  h1 {     color: @color1; }  h3 {     color: @color2; } 

To compile the above LESS code into normal CSS, run the following command:

lessc styles.less styles.css

styles.css: The output CSS file will be as follows:

styles.css
h1 {     color: hsla(150, 100%, 50%, 0.3); }  h3 {     color: #ff7f50; } 

Output:

 

Example 2: In this example, we have made the text color of the h1 tag using the hsl() function. Using hsv() function, we have defined @color1 using hsva() function and defined @color2 with the hsv() function. We have applied @color1 as the normal background-color of the h3 tag and @color2 as the background-color on hover.

HTML
<!DOCTYPE html> <html lang="en"> <head>     <title>Color Definition Functions in Less.js</title>     <link rel="stylesheet"            href="styles.css"> </head> <body>     <h1>GeeksforGeeks</h1>     <h3>Color Definition Functions in Less.js</h3> </body> </html> 

styles.less: The LESS code is as follows:

styles.less
@color1: hsv(10, 80%, 90%); @color2: hsva(10, 80%, 90%, 0.3);  h1 {     color: rgb(5, 255, 130); }  h3 {     background-color: @color1; }  h3:hover {     background-color: @color2; } 

To compile the above LESS code into normal CSS, run the following command:

lessc styles.less styles.css

styles.css: The output CSS file comes out to be as follows

styles.css
h1 {     color: #05ff82; }  h3 {     background-color: #e64c2e; }  h3:hover {     background-color: rgba(230, 76, 46, 0.3); } 

Output:

 

Reference: https://lesscss.org/functions/#color-definition


Next Article
Less.js Color Definition hsl() Function
author
mycodenotein
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • LESS
  • Less.js-Functions

Similar Reads

  • Less.js Color Definition hsl() 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 Definition hsv() 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 Definition hsva() 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
    4 min read
  • Less.js Color Definition hsla() 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 Definition rgb() 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 Definition rgba() 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 Definition argb() Function
    Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. CSS is more beneficial because it makes use of a dynamic style sheet language. LESS is flexible enough to work in a wide range of browsers. The CSS pre-processor i
    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 Misc color() Function
    Less.js is a simple CSS pre-processor that facilitates the creation of manageable, customizable, and reusable style sheets for websites. Since CSS is a dynamic style sheet language, it is preferred. LESS is adaptable, so it works with a wide range of browsers. Only CSS that has been created and proc
    3 min read
  • Less.js Color Blending exclusion() 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
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences