Color Manipulation Methods
Learn how to darken, lighten, desaturate, and blend colors with the Color class.
Color Manipulation Methods
applyOpacity()
Applies the specified opacity percentage to the color, returning a new Color instance.
This is an absolute setter: passing
50means "set opacity to exactly 50%", regardless of the current opacity.
Signature
applyOpacity(opacity: Percent): ColorParameters
| Parameter | Type | Description |
|---|---|---|
opacity | Percent | The opacity percentage (0–100) to apply. |
Returns
Color: A newColorinstance with the modified opacity. If the original color has no alpha channel, it is added. If it already has one, it is replaced.
Example
applyDarkness()
Darkens the color by subtracting the given percentage points from the current lightness in HSL space.
This is a relative adjustment: passing
20means "reduce lightness by 20 percentage points" from its current value.
Signature
applyDarkness(percent: Percent): ColorParameters
| Parameter | Type | Description |
|---|---|---|
percent | Percent | Percentage points to subtract from lightness (0–100). |
Returns
Color: A new darkenedColorinstance. Reduces lightness in HSL space, clamping to0%if the result would be negative. The original alpha (opacity) is preserved.
Example
applyBrightness()
Lightens the color by adding the given percentage points to the current lightness in HSL space.
This is a relative adjustment: passing
30means "increase lightness by 30 percentage points" from its current value.
Signature
applyBrightness(percent: Percent): ColorParameters
| Parameter | Type | Description |
|---|---|---|
percent | Percent | Percentage points to add to lightness (0–100). |
Returns
Color: A new lightenedColorinstance. Increases lightness in HSL space, clamping to100%if the result exceeds it. The original alpha (opacity) is preserved.
Example
applyDullness()
Desaturates the color by subtracting the given percentage points from the current saturation in HSL space.
This is a relative adjustment: passing
50means "reduce saturation by 50 percentage points" from its current value.
Signature
applyDullness(percent: Percent): ColorParameters
| Parameter | Type | Description |
|---|---|---|
percent | Percent | Percentage points to subtract from saturation (0–100). |
Returns
Color: A new desaturatedColorinstance. Reduces saturation in HSL space, clamping to0%if the result would be negative. The original alpha (opacity) is preserved.
Example
applyWhiteShade()
Softens the color toward white by proportionally reducing saturation and increasing lightness.
This is a proportional blend: passing
40means "move 40% of the remaining distance toward pure white". UnlikeapplyBrightnessorapplyDullness, the effect scales relative to the current distance from white, producing a natural pastel/tint effect.
Signature
applyWhiteShade(percent: Percent): ColorParameters
| Parameter | Type | Description |
|---|---|---|
percent | Percent | Soften percentage (0–100). |
Returns
Color: A new softenedColorinstance. Internally reduces saturation and increases lightness proportionally. The original alpha (opacity) is preserved.
Example
blendWith()
Blends the current color with another color by a given weight.
Signature
blendWith(other: ColorType | CSSColor, weight?: number): ColorParameters
| Parameter | Type | Description |
|---|---|---|
other | ColorType | CSSColor | The color to blend with. |
weight | number (optional) | The influence of the other color (0–1, default 0.5). |
Returns
Color: A new blendedColorinstance. A weight of0returns the original color,1returns the other color, and0.5is an equal mix.
Example
Last updated: Mon, Jun 15, 2026 09:49:35PM (UTC)
