Skip to content

Manipulation ​

Compare adjustments to see how the same amount affects lightness, RGB channels, and opacity.

xcolor provides a series of manipulation methods based on HSL and RGB color spaces. All manipulation methods modify the instance in place and return this, supporting chaining.

TIP

If you need to preserve the original color, call .clone() first.

Brightness ​

Original L=50%lighten(20) → L=60%darken(20) → L=40%

lighten(amount) ​

Move HSL lightness toward white across the remaining range. amount is the percentage of the distance from the current lightness to 100%, default 10, range 0–100; 50 moves halfway and 100 always produces white.

ts
xcolor('#ff0000').lighten(20).toHex() // '#ff3333'
xcolor('#ff0000').lighten().toHex()   // '#ff1a1a' (default 10)
→lighten(20)→

darken(amount) ​

Move HSL lightness toward black across the current range. amount is the percentage of the distance from the current lightness to 0%, default 10, range 0–100; 100 always produces black. Equivalent to lighten(-amount).

ts
xcolor('#ff0000').darken(20).toHex() // '#cc0000'
→darken(20)→

brighten(amount) ​

RGB(51,102,204)+30%RGB(112,147,219)Each channel → 255R = 51 + (255-51)×0.3= 112.2

Push each RGB channel toward 255 directly in RGB space. Unlike lighten, brighten does not go through HSL conversion, producing a more "whitened" effect. Default 10, range 0–100.

ts
xcolor('#ff0000').brighten(50).toHex() // '#ff8080'
→brighten(50)→

Saturation ​

S = 0%S = 100%Original S=50%saturate(20)desaturate(20)

saturate(amount) ​

Increase HSL saturation. Default 10, range 0–100.

ts
xcolor('#bf4040').saturate(40).toHex() // '#f20d0d'

desaturate(amount) ​

Decrease HSL saturation. Equivalent to saturate(-amount), default 10.

ts
xcolor('#ff0000').desaturate(50).toHex() // '#bf4040'
→desaturate(50)→

grayscale() ​

OriginalS → 0GrayscaleKeeps hue & lightnessSets saturation to 0

Fully desaturate, equivalent to desaturate(100). Alias: greyscale().

ts
xcolor('#ff0000').grayscale().toHex() // '#808080'
→grayscale()→

Hue Rotation ​

spin(90)H: 0° → 90°

spin(degrees) ​

Rotate hue on the HSL color wheel. Accepts positive or negative degrees, automatically wraps at 360°. Alias: rotate().

ts
xcolor('#ff0000').spin(120).toHex()  // '#00ff00' — rotate 120°
xcolor('#ff0000').spin(-120).toHex() // '#0000ff' — rotate -120°
xcolor('#ff0000').spin(180).toHex()  // '#00ffff' — complementary color
→spin(120)→
→spin(120)→

Inversion ​

RGB(50,100,200)255 − cRGB(205,155,55)R: 255 − 50 = 205G: 255 − 100 = 155B: 255 − 200 = 55

negate() ​

Invert each RGB channel (255 - channel), alpha remains unchanged. Alias: invert().

ts
xcolor('#ff0000').negate().toHex() // '#00ffff'
xcolor('#ffffff').negate().toHex() // '#000000'
→negate()→

Opacity ​

α = 0α = 1α = 0.6fade(0.2)opaquer(0.2)

fade(amount) ​

Decrease opacity (make more transparent). Alpha reduced by amount / 100, default 10. Alias: fadeOut().

ts
xcolor('#ff0000').fade(50).alpha()   // 0.5

opaquer(amount) ​

Increase opacity. Alpha increased by amount / 100, default 10. Alias: fadeIn().

ts
xcolor('rgba(255,0,0,0.5)').opaquer(30).alpha() // 0.8

Mixing ​

mix+=50% blendtint+=mix with whiteshade+=mix with black

mix(color, amount) ​

Linear interpolation with another color in RGB space. amount is the weight of the target color (0–100), default 50.

  • 0 = fully keep current color
  • 50 = equal mix
  • 100 = fully become target color
ts
xcolor('#ff0000').mix('#0000ff', 50).toHex() // '#800080' — purple
+
→mix(50)→

tint(amount) ​

Mix with white. amount is white's weight, default 50.

ts
xcolor('#ff0000').tint(50).toHex()  // '#ff8080'
xcolor('#ff0000').tint(100).toHex() // '#ffffff'
→tint(50)→

shade(amount) ​

Mix with black. amount is black's weight, default 50.

ts
xcolor('#ff0000').shade(50).toHex()  // '#800000'
xcolor('#ff0000').shade(100).toHex() // '#000000'
→shade(50)→

Quick Reference ​

MethodDefaultColor SpaceDescriptionAlias
lighten(amount)10HSLIncrease lightness—
darken(amount)10HSLDecrease lightness—
brighten(amount)10RGBPush channels toward 255—
saturate(amount)10HSLIncrease saturation—
desaturate(amount)10HSLDecrease saturation—
grayscale()—HSLFully desaturategreyscale()
spin(degrees)—HSLRotate huerotate()
negate()—RGBInvertinvert()
fade(amount)10—Decrease opacityfadeOut()
opaquer(amount)10—Increase opacityfadeIn()
mix(color, amount)50RGBMix with any color—
tint(amount)50RGBMix with white—
shade(amount)50RGBMix with black—

Want richer color operations? Check out the Plugin System — the blend plugin provides 11 blend modes, and the scale plugin supports color space interpolation with easing functions.

Choosing an operation ​

GoalMethodsResult and alpha
Lighten in HSL or RGBlighten, brightenMutate the instance and preserve alpha
Mix toward white or another colortint, mixMutate the instance and interpolate alpha
Composite layersblendReturns a new color, with source-over alpha
Generate colors between endpointsgradient, scaleReturn new colors and interpolate alpha. Steps range from 2 to 10,000.
Generate design tokenspaletteReturns a list keyed by the requested shade order. Built-in generators emit opaque colors. A custom generator must return one valid color per shade.

Creation returns an invalid black fallback when parsing fails. Check isValid() before using external inputs in operations. A failed hex(value) setter throws and retains the current channels while marking the instance invalid. An unknown blend mode throws.

Released under the MIT License.