Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • 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
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
SASS | Color Functions
Next article icon

SASS | Color Functions

Last Updated : 19 May, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
Color Components: Before we move to the SASS color functions, let's make sure we know the elements of color that they change. The simple color theory divides any color into three basic components: hue, saturation, and value.
  • HUE (also called "local color") is generally the color that we talk about. Like: Blue Sky, Yellow sun.
  • Saturation is the measure that tells the amount of hue existing in the color i.e. color intensity. For example, the color of clouds changes from white to blue to black.
  • The value is the measure of the lightness or darkness of the color. For example, a plain brown ground with some part in sunlight and the other in shadow.
Color Models: In a technological world, colors are represented as either RGB or HSL. (There are various other models like CMYK and LAB, but only RGB and HSL are the ones relevant to SASS development.) RGB values are the measure of the amount of "red" "green" and "blue" in the basic color. Every component is a value between 0 (color not present) to 255 (complete color). RGB colors are basically expressed in hexadecimal like #0000ff or #2abd35. HSL stands for "Hue, Saturation, and Lightness". One might also get HSV (here the V stands for "value"), or HSB (here the B stands for "brightness") models. For example, Photoshop uses HSB. hsl($hue, $saturation, $value): Hue is indicated as a degree on the wheel of colors (pure red is at 0, pure green at 120, and pure blue at 240), whereas saturation and value are indicated as percentages. This is a quite simple example. While changing between RGB and HSL, the hue component of color can sometimes get quite ugly. For example, the hue of #ac4138 is 4.65517 degrees. opacity: In both the RGB and HSL color models, opacity is given via an alpha value between 0 to 100%, with 0 being fully transparent and 100% being fully opaque. SASS Color Functions: The rgb() and hsl() are used for making more brief CSS. All the modern browsers support rgba() and hsla() CSS functions, so the SASS transpiler will keep the functions the same in the CSS. The rest three functions, "grayscale(), invert() and complement()" make a new color based on the current one. Invert() function, inverts each red, green and blue value and complement(), rotates the color 180 degrees, gives quite similar but not identical results.
  1. rgb($red, $green, $blue): This method creates an opaque color based on the given decimal values or percentages.
    • Example: CSS
            rgb(252, 186, 3)        
    • Output:
      #fcba03
      CSS
            rgb(50%, 50%, 100%)        
    • Output:
      #8080ff
  2. rgba($red, $green, $blue, $alpha): This method creates a color based on the given decimal or percentage values at the given opacity.
    • Example: CSS
            rgba(71, 214, 75, 0.5 )        
    • Output:
      rgba(71, 214, 75, 0.5 )
  3. hsl($hue, $saturation, $lightness): This method creates an opaque color based on the given hue (in degrees), saturation and lightness (in percentages).
    • Example: CSS
            hsl(122, 64, 56)        
    • Output:
      #47d74c
  4. hsla($hue, $saturation, $lightness, $alpha): This method create a color based on the specified hue, saturation and lightness at the specified opacity.
    • Example: CSS
            hsla(122, 64, 56, 50)        
    • Output:
       hsla(122, 64, 56, 50)
  5. grayscale($color): This method returns a gray value that has the same intensity as "color".
    • Example: CSS
            grayscale(#ad4038)        
    • Output:
      #737373
  6. complement($color): This method returns a color that has the same saturation and value, but has a hue 180 degrees different from the hue of "color".
    • Example: CSS
            complement(#47d74c)        
    • Output:
      #d747d2
  7. invert($color): This method returns the inverse of the individual red, green and blue components of "color".
    • Example: CSS
            invert(#ad4038)        
    • Output:
      #52bfc7
SASS Component Extraction Functions:
  1. red($color): This method returns the red component of "color".
    • Example: CSS
            red(#d747d2)        
    • Output:
      215
  2. green($color): This method returns the green component of "color".
    • Example: CSS
            green(#d747d2)        
    • Output:
      71
  3. blue($color): This method returns the blue component of "color".
    • Example: CSS
            blue(#d747d2)        
    • Output:
      210
  4. hue($color): This method returns the hue component of "color".
    • Example: CSS
            hue(#d747d2)        
    • Output:
       302°
  5. saturation($color): This method returns the saturation component of "color".
    • Example: CSS
            saturation(#d747d2)        
    • Output:
      64%
  6. lightness($color): This method returns the lightness component of "color".
    • Example: CSS
            lightness(#d747d2)        
    • Output:
      56%
  7. alpha($color): This method returns the alpha channel of color as a number between 0 and 1.
    • Example: CSS
            alpha(#d747d2)        
    • Output:
      1
  8. opacity($color): This method returns the opacity of color as a number between 0 and 1.
    • Example: CSS
            opacity(rgba(215, 71, 210, 0.7);        
    • Output:
      0.7
SASS Manipulate Color Functions
  1. mix($color1, $color2, $weight): This method creates a color that is the combination of color1 and color2. The weight parameter must be between 0% and 100%. A larger weight means that more of color1 should be used. A smaller weight means that more of color2 should be used. The default value is 50%.
  2. adjust-hue($color, $degrees): This method adjusts the color's hue with a degree from -360deg to 360deg.
    • Example: CSS
            adjust-hue(#7fffd4, 80deg);        
    • Output:
      #8080ff
  3. adjust-color($color, $red, $green, $blue, $hue, $saturation, $lightness, $alpha): This method adjusts one or more parameters by the given amount. This function adds or subtracts the given amount to/from the existing color value.
  4. change-color($color, $red, $green, $blue, $hue, $saturation, $lightness, $alpha): This method sets one or more parameters of a color to new values.
    • Example: CSS
            change-color(#7fffd4, red: 255);        
    • Output:
       #ffffd4
  5. scale-color($color, $red, $green, $blue, $saturation, $lightness, $alpha): This method scales one or more parameters of color.
  6. rgba($color, $alpha): This method creates a new color with the given alpha channel.
    • Example: CSS
            rgba(#7fffd4, 30%)        
    • Output:
      rgba(127, 255, 212, 0.3)
  7. lighten($color, $amount): This method creates a lighter color with the amount between 0% and 100%. The amount parameter increases the HSL lightness by that percent.
  8. darken($color, $amount): This method creates a darker color with the amount between 0% and 100%. The amount parameter decreases the HSL lightness by that percent.
  9. saturate($color, $amount): This method creates a more saturated color with the amount between 0% and 100%. The amount parameter increases the HSL saturation by that percent.
  10. desaturate($color, $amount): This method creates a less saturated color with the amount between 0% and 100%. The amount parameter decreases the HSL saturation by that percent.
  11. opacify($color, $amount): This method creates a more opaque color with the amount between 0 and 1. The amount parameter increases the alpha channel by that amount.
  12. V: This method creates a more opaque color with the amount between 0 and 1. The amount parameter increases the alpha channel by that amount.
  13. transparentize($color, $amount): This method creates a more transparent color with the amount between 0 and 1. The amount parameter decreases the alpha channel by that amount.
  14. fade-out($color, $amount): This method creates a more transparent color with the amount between 0 and 1. The amount parameter decreases the alpha channel by that amount.

Next Article
SASS | Color Functions

S

Slash_IT
Improve
Article Tags :
  • Web Technologies
  • CSS
  • Write From Home
  • SASS

Similar Reads

    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 Channel Functions
    In this article, we will take a look at various Color Channel functions provided by Less.js. Less (Leaner Style Sheets) is an extension to normal CSS, which basically enhances the abilities of normal CSS and gives it superpowers. Color Channel functions are built in Less.js to basically extract a co
    5 min read
    SASS | Map Functions
    The SASS Map data-type is used to display one or more key-value pairs. Along with the map functions shown in the below lists, you can also use any of the SASS list functions with maps as well. The following lists contains all map functions in SASS: map-has-key($map, $key) function: This function ret
    1 min read
    p5.js colorMode() Function
    The colorMode() function is an inbuilt function in p5.js which is used to let the user choose between RGB or HSB color options. The RGB color mode is by default. Thus, the parameters that which the user passes into it corresponds to red, green and blue values. The user creates various colors by pass
    2 min read
    Less.js Color Blending Functions
    In this article, we are going to see Color Blending Functions in Less.js.  Less (Leaner Style Sheets) is an extension to normal CSS code which basically enhances the abilities of normal CSS and provides it superpowers. Color blending functions are provided by Less.js to basically perform blending op
    5 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