Sass and Compass provide a number of useful functions you can use to alter and manipulate colors with ease. Most color functions operate on a single color, but some can be used to combine two colors in different ways. Our "base color" and "alternate color" will be used throughout the examples.
— The color for which all color operations are based on.
$color
— The alternate color used in functions that operate on more than one color.
$color-alt
— Creates a color from red, green, and blue values.
rgb($r, $g, $b)
— Creates a color from red, green, blue, and alpha values.
rgba($r, $g, $b, .5)
— Mixes two colors together.
mix($color, $color-alt)
mix($color, $color-alt, 20%)
— Gets the red component of a color.
red($color)
— Gets the green component of a color.
green($color)
— Gets the blue component of a color.
blue($color)
— Creates a color from hue, saturation, and lightness values.
hsl($h, $s, $l)
— Creates a color from hue, saturation, lightness, and alpha values.
hsla($h, $s, $l, .5)
— Changes the hue of a color.
adjust-hue($color, 20deg)
adjust-hue($color, -20deg)
— Makes a color lighter.
lighten($color, 20%)
— Makes a color darker.
darken($color, 20%)
— Makes a color more saturated.
saturate($color, 20%)
— Makes a color less saturated.
desaturate($color, 20%)
— Converts a color to grayscale.
grayscale($color)
— Returns the complement of a color.
complement($color)
— Returns the inverse of a color.
invert($color)
— Gets the hue component of a color.
hue($color)
— Gets the saturation component of a color.
saturation($color)
— Gets the lightness component of a color.
lightness($color)
— Changes the alpha component for a color.
rgba($color, .5)
— Makes a color more opaque.
opacify($color, .5)
— Makes a color more transparent.
transparentize($color, .5)
— Gets the alpha component (opacity) of a color.
alpha($color)
— Increases or decreases one or more components of a color.
adjust-color($color, $red: -50, $green: 20, $blue: 220)
adjust-color($color, $hue: 120deg, $saturation: 30, $lightness: 10)
— Fluidly scales one or more properties of a color.
scale-color($color, $red: 10%, $green: 90%, $blue: 20%)
scale-color($color, $saturation: -30%, $lightness: 20%, $alpha: 10%)
— Changes one or more properties of a color.
change-color($color, $red: 255, $green: 60, $blue: 170)
change-color($color, $hue: 190deg, $saturation: 50%, $lightness: 25%)
— Adds $amount to $color's lightness value. $amount can be negative.
adjust-lightness($color, 20%)
adjust-lightness($color, -20%)
— Adds $amount to $color's saturation value. $amount can be negative.
adjust-saturation($color, 20%)
adjust-saturation($color, -20%)
— Scales $color's lightness value by $amount. $amount can be negative.
scale-lightness($color, 20%)
scale-lightness($color, -20%)
— Scales $color's saturation value by $amount. $amount can be negative.
scale-saturation($color, 20%)
scale-saturation($color, -20%)
— Darkens the $color by mixing it with black as specified by $percentage.
shade($color, 20%)
— Lightens the $color by mixing it with white as specified by $percentage.
tint($color, 20%)
— Returns the $light color when the $color is dark and the $dark color when the $color is light.
contrast-color($color)
contrast-color($color, shade($color, 75%), tint($color, 75%), 30%)