Color functions are among the most useful built-in tools in LESS, letting you derive hover states, borders, and theme variants from a single base color instead of hand-picking every shade manually.
What Do LESS Color Functions Do?
LESS color functions take a color value (and usually a percentage or amount) and return a new, derived color. Internally, most operate on the HSL representation of a color, adjusting lightness, saturation, or hue.
Because these functions run at compile time, every derived color is a fixed, static value in the output CSS, there's no runtime color computation happening in the browser.
Most color functions accept a color followed by a percentage amount.
lighten() and darken() adjust the HSL lightness channel by the given percentage.
fade() sets absolute alpha transparency; fadein()/fadeout() adjust it relatively.
Channel extraction functions (red(), hue(), lightness()) return a single numeric value from a color.
LESS Color Functions Cheatsheet
The most commonly used color functions and what each one does.
Function
Example
Effect
lighten()
lighten(@c, 10%)
Increases HSL lightness
darken()
darken(@c, 10%)
Decreases HSL lightness
saturate()
saturate(@c, 20%)
Increases HSL saturation
desaturate()
desaturate(@c, 20%)
Decreases HSL saturation
fade()
fade(@c, 50%)
Sets absolute alpha to 50%
fadein() / fadeout()
fadeout(@c, 10%)
Adjusts alpha relatively
mix()
mix(@a, @b, 50%)
Blends two colors together
spin()
spin(@c, 30)
Rotates hue by degrees
contrast()
contrast(@c, #000, #fff)
Picks readable light/dark text
red()/green()/blue()
red(@c)
Extracts a single RGB channel
Adjusting Lightness and Saturation
lighten() and darken() are the two most frequently used color functions, ideal for generating hover, active, and border states from a single brand color without hardcoding a separate hex value for each state.
fade(@color, @amount) sets the color's alpha channel to an absolute percentage, while fadein() and fadeout() adjust the current alpha relatively, useful for building overlay and disabled states.
mix() blends two colors together by a weighted percentage, and spin() rotates a color's hue around the color wheel, both useful for generating a broader palette from a small set of brand colors.
@blend: mix(#2563eb, #f59e0b, 50%); // an even blend of blue and amber
@complementary: spin(#2563eb, 180); // rotates hue 180 degrees
spin() wraps around the 360-degree hue wheel, so spin(@c, 380) behaves the same as spin(@c, 20).
Common Mistakes
Hardcoding a separate hex value for every hover and active state instead of deriving them from one base color.
Confusing fade() (sets absolute alpha) with fadeout() (adjusts alpha relatively); they behave very differently.
Assuming color functions operate on RGB channels directly; most operate on HSL (hue, saturation, lightness) internally.
Overusing spin() for large hue rotations, which can produce colors that clash with an established brand palette.
Key Takeaways
Color functions derive new colors from a base color, computed once at compile time.
mix() blends two colors, and spin() rotates hue, both useful for generating broader palettes.
Pro Tip
Define a small set of brand colors as variables, then derive every hover, active, border, and disabled state from them using color functions. This keeps your palette consistent and makes rebranding a matter of changing just a few base variables.
You now understand LESS's color function library. Next, explore string functions for building dynamic text values.