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.
- 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
- Example:
- 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 )
- Example:
- 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
- Example:
- 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)
- Example:
- grayscale($color): This method returns a gray value that has the same intensity as "color".
- Example:
CSS grayscale(#ad4038)
- Output:
#737373
- Example:
- 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
- Example:
- invert($color): This method returns the inverse of the individual red, green and blue components of "color".
- Example:
CSS invert(#ad4038)
- Output:
#52bfc7
- Example:
- red($color): This method returns the red component of "color".
- Example:
CSS red(#d747d2)
- Output:
215
- Example:
- green($color): This method returns the green component of "color".
- Example:
CSS green(#d747d2)
- Output:
71
- Example:
- blue($color): This method returns the blue component of "color".
- Example:
CSS blue(#d747d2)
- Output:
210
- Example:
- hue($color): This method returns the hue component of "color".
- Example:
CSS hue(#d747d2)
- Output:
302°
- Example:
- saturation($color): This method returns the saturation component of "color".
- Example:
CSS saturation(#d747d2)
- Output:
64%
- Example:
- lightness($color): This method returns the lightness component of "color".
- Example:
CSS lightness(#d747d2)
- Output:
56%
- Example:
- alpha($color): This method returns the alpha channel of color as a number between 0 and 1.
- Example:
CSS alpha(#d747d2)
- Output:
1
- Example:
- 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
- Example:
- 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%.
- 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
- Example:
- 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.
- 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
- Example:
- scale-color($color, $red, $green, $blue, $saturation, $lightness, $alpha): This method scales one or more parameters of color.
- 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)
- Example:
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.