Class Colors
Color Overview for a detailed guide to color spaces, formats, manipulation, CSS color relationships, and palettes. The core entry points are getColor() to parse any color into a Color object (with RGB, HSL, and oklch properties pre-computed), getString() to convert back to a CSS string, and getValues() for raw numeric components in a single color space. adjust() is the general-purpose manipulation method - all convenience methods like lighten(), saturate(), etc. delegate to it.
See the Color Overview for a full guide organized by topic: conversion, inspection, manipulation (including alpha compositing), palettes and harmony, theme generation, and CSS color relationships.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringThe general-purpose method for deriving a related color from a base color.static Stringadjust(String color, Map deltas, ColorFormat outputFormat) The general-purpose method for deriving a related color from a base color.static String[]Returns a set of analogous colors - hues near the original, evenly spaced within a segment of the color wheel.static String[]Seeanalogous()static String[]Seeanalogous()static String[]analogous(Color color, int results, int slices, ColorFormat outputFormat) Returns a set of analogous colors - hues near the original, evenly spaced within a segment of the color wheel.static String[]Returns a set of analogous colors - hues near the original, evenly spaced within a segment of the color wheel.static String[]Seeanalogous()static String[]Seeanalogous()static String[]analogous(String color, int results, int slices, ColorFormat outputFormat) Returns a set of analogous colors - hues near the original, evenly spaced within a segment of the color wheel.static ColorautoContrast(Color background) Returns a text color that meets a target contrast ratio against the given background.static ColorautoContrast(Color background, Map options) Returns a text color that meets a target contrast ratio against the given background.static ColorautoContrast(String background) Returns a text color that meets a target contrast ratio against the given background.static ColorautoContrast(String background, Map options) Returns a text color that meets a target contrast ratio against the given background.static StringReturns a brighter, more vivid version of the given color by boosting both chroma (color intensity) and lightness together.static Stringbrighten(String color, double amount, ColorFormat outputFormat) Returns a brighter, more vivid version of the given color by boosting both chroma (color intensity) and lightness together.static String[]colorScale(Color color1, Color color2, int steps) Generates an array of evenly-spaced colors between twoColorendpoints, interpolated in the oklch color space for perceptual uniformity.static String[]colorScale(Color color1, Color color2, int steps, ColorFormat format) Generates an array of evenly-spaced colors between twoColorendpoints, interpolated in the oklch color space for perceptual uniformity.static String[]colorScale(Color color1, Color color2, int steps, ColorFormat format, ColorFormat space) Generates an array of evenly-spaced colors between twoColorendpoints, interpolated in the specified color space.static String[]colorScale(String color1, String color2, int steps) Generates an array of evenly-spaced colors between two endpoints, interpolated in oklch by default.static String[]colorScale(String color1, String color2, int steps, ColorFormat format) Generates an array of evenly-spaced colors between two endpoints, interpolated in the oklch color space for perceptual uniformity.static String[]colorScale(String color1, String color2, int steps, ColorFormat format, ColorFormat space) Generates an array of evenly-spaced colors between two endpoints, interpolated in the specified color space.static Stringcomplement(Color color) Returns the complementary color - the hue on the opposite side of the color wheel (rotated by 180 degrees).static Stringcomplement(Color color, ColorFormat outputFormat) Returns the complementary color - the hue on the opposite side of the color wheel (rotated by 180 degrees).static Stringcomplement(String color) Returns the complementary color - the hue on the opposite side of the color wheel (rotated by 180 degrees).static Stringcomplement(String color, ColorFormat outputFormat) Returns the complementary color - the hue on the opposite side of the color wheel (rotated by 180 degrees).static DoubleReturns the approximate perceptual contrast ratio between twoColorobjects, based on oklch lightness.static DoubleReturns the approximate perceptual contrast ratio between two colors, based on oklch lightness.static StringReturns a darker version of the given color.static Stringdarken(String color, double amount, ColorFormat outputFormat) Returns a darker version of the given color.static Stringdesaturate(String color, double amount) Returns a more muted version of the given color by reducing its chroma (color intensity).static Stringdesaturate(String color, double amount, ColorFormat outputFormat) Returns a more muted version of the given color by reducing its chroma (color intensity).static MapdescribeRelationship(String baseColor, String derivedColor) Computes the perceptual relationship between two colors in oklch space and returns a structured description.static StringReturns a dimmer, less vivid version of the given color — the inverse ofbrighten().static Stringdim(String color, double amount, ColorFormat outputFormat) Returns a dimmer, less vivid version of the given color — the inverse ofbrighten().static DoubleReturns a number indicating how different twoColorobjects look to the human eye.static DoubleReturns a number indicating how different two colors look to the human eye.static BooleanReturns true if twoColorobjects represent the same color (same R, G, B, and alpha).static BooleanReturns true if two color values represent the same color (same R, G, B, and alpha), regardless of input format.static StringReturns an opaque color visually equivalent to the given semi-transparentColorcomposited over a background (default white).static StringFlattens a semi-transparentColoragainst a background.static Stringflatten(Color color, Color background, ColorFormat outputFormat) Flattens a semi-transparentColoragainst a background, returning the result in the specified format.static StringReturns an opaque color visually equivalent to the given semi-transparent color composited over a background (default white).static StringFlattens a semi-transparent color against a background.static Stringflatten(String color, String background, ColorFormat outputFormat) Flattens a semi-transparent color against a background, returning the result in the specified format.static StringgenerateCSS(String origin, Map relationship) Converts an oklch relationship descriptor (as returned bydescribeRelationship()orparseRelationship()) into a CSS Relative Color Syntax expression.static DoubleReturns the alpha (opacity) component of the given color as a float from 0.0 (fully transparent) to 1.0 (fully opaque).static DoubleReturns the alpha (opacity) component of the given color as a float from 0.0 (fully transparent) to 1.0 (fully opaque).static ColorParses any valid CSS color into a structuredColorobject with RGB, HSL, and oklch properties pre-computed, plus convenience methods for manipulation.static ColorParses any valid CSS color into a structuredColorobject with RGB, HSL, and oklch properties pre-computed, plus convenience methods for manipulation.static ColorParses any valid CSS color into a structuredColorobject with RGB, HSL, and oklch properties pre-computed, plus convenience methods for manipulation.static ColorFormatReturns theColorFormatof the given color string, or null if the value is not a valid color.static StringgetString(String color, ColorFormat format) Converts any valid CSS color to a string in the specified format.static MapgetValues(String color, ColorFormat format) Returns a plain object with color component values in the requested format.static booleanReturns true if the given value is a valid CSS color specification.static booleanisColor(Color color, ColorFormat format) Returns true if the given value is a valid CSS color specification.static booleanReturns true if the given value is a valid CSS color specification.static booleanisColor(String color, ColorFormat format) Returns true if the given value is a valid CSS color specification.static booleanReturns true if the given value is a valid CSS color specification.static booleanisColor(Map color, ColorFormat format) Returns true if the given value is a valid CSS color specification.static BooleanReturns true if the given color is perceptually dark (i.e.static BooleanReturns true if the given color is perceptually dark (i.e.static StringReturns a lighter version of the given color.static Stringlighten(String color, double amount, ColorFormat outputFormat) Returns a lighter version of the given color.static StringBlends twoColorobjects in the oklch color space.static StringBlends twoColorobjects in the oklch color space at the given ratio.static Stringmix(Color color1, Color color2, Double ratio, ColorFormat outputFormat) Blends twoColorobjects in the oklch color space at the given ratio, returning the result in the specified format.static StringBlends two colors in the oklch color space, producing a single result.static StringBlends two colors in the oklch color space at the given ratio.static Stringmix(String color1, String color2, Double ratio, ColorFormat outputFormat) Blends two colors in the oklch color space at the given ratio, returning the result in the specified format.static StringmostReadable(String background, String[] candidates) Returns the color fromcandidatesthat has the highest contrast againstbackground.static Color[]Generates a tonal ramp - an ordered series of colors at different lightness levels sharing the same hue.static Color[]Seepalette()static Color[]Generates a tonal ramp - an ordered series of colors at different lightness levels sharing the same hue.static Color[]Generates a tonal ramp - an ordered series of colors at different lightness levels sharing the same hue.static Color[]Seepalette()static Color[]Generates a tonal ramp - an ordered series of colors at different lightness levels sharing the same hue.static MapparseRelationship(String rcsExpr) Extracts structural information from a CSS Relative Color Syntax (RCS) expression - the origin reference, color space, and per-channel modifications - without evaluating it.static ColorresolveCSS(String expr) Resolves any CSS color expression to a flatColorby evaluating it through the browser's CSS engine.static ColorresolveCSS(String expr, Element element) Resolves any CSS color expression to a flatColorby evaluating it through the browser's CSS engine.static StringReturns a more vivid version of the given color by increasing its chroma (color intensity).static Stringsaturate(String color, double amount, ColorFormat outputFormat) Returns a more vivid version of the given color by increasing its chroma (color intensity).static MapGenerates a set of harmonious seed colors from a single primary.static MapGenerates a set of harmonious seed colors from a single primary.static MapGenerates a set of harmonious seed colors from a single primary.static MapGenerates a set of harmonious seed colors from a single primary.static StringReturns a new color string with the alpha (opacity) component replaced.static StringsetAlpha(String color, double alpha, ColorFormat outputFormat) Returns a new color string with the alpha (opacity) component replaced.static StringRotates the hue of a color by the given number of degrees (in oklch space).static Stringspin(String color, double degrees, ColorFormat outputFormat) Rotates the hue of a color by the given number of degrees (in oklch space).static String[]splitComplement(Color color) Returns three colors: the original plus two split-complement accents (hue +150 and +210 degrees - flanking the complement rather than hitting it directly).static String[]splitComplement(Color color, ColorFormat outputFormat) Returns three colors: the original plus two split-complement accents (hue +150 and +210 degrees - flanking the complement rather than hitting it directly).static String[]splitComplement(String color) Returns three colors: the original plus two split-complement accents (hue +150 and +210 degrees - flanking the complement rather than hitting it directly).static String[]splitComplement(String color, ColorFormat outputFormat) Returns three colors: the original plus two split-complement accents (hue +150 and +210 degrees - flanking the complement rather than hitting it directly).static String[]Returns four colors with hues spaced 90 degrees apart (square scheme).static String[]tetrad(Color color, ColorFormat outputFormat) Returns four colors with hues spaced 90 degrees apart (square scheme).static String[]Returns four colors with hues spaced 90 degrees apart (square scheme).static String[]tetrad(String color, ColorFormat outputFormat) Returns four colors with hues spaced 90 degrees apart (square scheme).static String[]Returns the three triadic colors (hues spaced 120 degrees apart).static String[]triad(Color color, ColorFormat outputFormat) Returns the three triadic colors (hues spaced 120 degrees apart).static String[]Returns the three triadic colors (hues spaced 120 degrees apart).static String[]triad(String color, ColorFormat outputFormat) Returns the three triadic colors (hues spaced 120 degrees apart).
-
Constructor Details
-
Colors
public Colors()
-
-
Method Details
-
adjust
The general-purpose method for deriving a related color from a base color. Accepts any combination of adjustment keys in thedeltasobject and returns the result as a CSS color string. Single-axis convenience wrappers -lighten(),darken(),saturate(),desaturate(), andcomplement()- all delegate to this method.Friendly percentage keys (recommended for most uses):
- lightness (-100 to 100): positive values lighten (toward white), negative darken (toward black). See
lighten()/darken. - saturation (-100 to 100): positive values intensify color, negative desaturate toward gray. See
saturate()/desaturate. - hue (degrees): signed rotation around the color wheel. See
complement()for the hue wheel reference. - alpha: signed delta to opacity (0 = transparent, 1 = opaque).
Raw oklch keys (for fine-grained control - see the oklch color space):
- L: signed delta to lightness (0-1). +0.1 is noticeably lighter.
- C: signed delta to chroma (0 = gray, max ~0.4). -0.05 desaturates subtly.
- h and alpha work the same as the friendly keys above.
rgb(...)input returnsrgb(...)output, etc.Examples:
- Parameters:
color- base color - any valid CSS color string or structured object fromgetColor()deltas- adjustment keys - any combination of friendly keys (lightness,saturation,hue,alpha) and/or raw oklch keys (L,C,h). See the key lists above.- Returns:
- CSS color string in the requested format, or null if the input is not a valid color
- See Also:
- lightness (-100 to 100): positive values lighten (toward white), negative darken (toward black). See
-
adjust
The general-purpose method for deriving a related color from a base color. Accepts any combination of adjustment keys in thedeltasobject and returns the result as a CSS color string. Single-axis convenience wrappers -lighten(),darken(),saturate(),desaturate(), andcomplement()- all delegate to this method.Friendly percentage keys (recommended for most uses):
- lightness (-100 to 100): positive values lighten (toward white), negative darken (toward black). See
lighten()/darken. - saturation (-100 to 100): positive values intensify color, negative desaturate toward gray. See
saturate()/desaturate. - hue (degrees): signed rotation around the color wheel. See
complement()for the hue wheel reference. - alpha: signed delta to opacity (0 = transparent, 1 = opaque).
Raw oklch keys (for fine-grained control - see the oklch color space):
- L: signed delta to lightness (0-1). +0.1 is noticeably lighter.
- C: signed delta to chroma (0 = gray, max ~0.4). -0.05 desaturates subtly.
- h and alpha work the same as the friendly keys above.
rgb(...)input returnsrgb(...)output, etc.Examples:
- Parameters:
color- base color - any valid CSS color string or structured object fromgetColor()deltas- adjustment keys - any combination of friendly keys (lightness,saturation,hue,alpha) and/or raw oklch keys (L,C,h). See the key lists above.outputFormat- format for the returned string; defaults to the detected format of the input color (hex for named colors)- Returns:
- CSS color string in the requested format, or null if the input is not a valid color
- See Also:
- lightness (-100 to 100): positive values lighten (toward white), negative darken (toward black). See
-
analogous
Returns a set of analogous colors - hues near the original, evenly spaced within a segment of the color wheel. Defaults to 6 results spanning 30 degrees.- Parameters:
color- base color- Returns:
- CSS color strings
-
analogous
Returns a set of analogous colors - hues near the original, evenly spaced within a segment of the color wheel. Defaults to 6 results spanning 30 degrees.- Parameters:
color- base color- Returns:
- CSS color strings
-
analogous
Seeanalogous() -
analogous
Seeanalogous() -
analogous
Seeanalogous() -
analogous
Seeanalogous() -
analogous
Returns a set of analogous colors - hues near the original, evenly spaced within a segment of the color wheel. Defaults to 6 results spanning 30 degrees.- Parameters:
color- base colorresults- number of colors to return (default 6)slices- how many slices to divide the wheel into (default 30, meaning each step is 12 degrees)outputFormat- output format; defaults to input format- Returns:
- CSS color strings
-
analogous
Returns a set of analogous colors - hues near the original, evenly spaced within a segment of the color wheel. Defaults to 6 results spanning 30 degrees.- Parameters:
color- base colorresults- number of colors to return (default 6)slices- how many slices to divide the wheel into (default 30, meaning each step is 12 degrees)outputFormat- output format; defaults to input format- Returns:
- CSS color strings
-
autoContrast
Returns a text color that meets a target contrast ratio against the given background. Useful for ensuring readability - given any background color, this method finds a foreground color that passes WCAG accessibility guidelines.By default, tries white first (preferred for dark backgrounds) and falls back to black. When
tintis true, the result is lightly tinted toward the background's hue for a more polished look, while still meeting the contrast target.- Parameters:
background- the background color to find a readable text color for- Returns:
- a Color meeting the contrast target, or the best available if the target cannot be met
- See Also:
-
autoContrast
Returns a text color that meets a target contrast ratio against the given background. Useful for ensuring readability - given any background color, this method finds a foreground color that passes WCAG accessibility guidelines.By default, tries white first (preferred for dark backgrounds) and falls back to black. When
tintis true, the result is lightly tinted toward the background's hue for a more polished look, while still meeting the contrast target.- Parameters:
background- the background color to find a readable text color for- Returns:
- a Color meeting the contrast target, or the best available if the target cannot be met
- See Also:
-
autoContrast
Returns a text color that meets a target contrast ratio against the given background. Useful for ensuring readability - given any background color, this method finds a foreground color that passes WCAG accessibility guidelines.By default, tries white first (preferred for dark backgrounds) and falls back to black. When
tintis true, the result is lightly tinted toward the background's hue for a more polished look, while still meeting the contrast target.- Parameters:
background- the background color to find a readable text color foroptions- optional settings:target- minimum contrast ratio (default 4.5 for WCAG AA; use 7.0 for WCAG AAA)prefer-"white"(default) or"black"; which extreme to try firsttint- if true, lightly tint the result toward the background's hue (default false)
- Returns:
- a Color meeting the contrast target, or the best available if the target cannot be met
- See Also:
-
autoContrast
Returns a text color that meets a target contrast ratio against the given background. Useful for ensuring readability - given any background color, this method finds a foreground color that passes WCAG accessibility guidelines.By default, tries white first (preferred for dark backgrounds) and falls back to black. When
tintis true, the result is lightly tinted toward the background's hue for a more polished look, while still meeting the contrast target.- Parameters:
background- the background color to find a readable text color foroptions- optional settings:target- minimum contrast ratio (default 4.5 for WCAG AA; use 7.0 for WCAG AAA)prefer-"white"(default) or"black"; which extreme to try firsttint- if true, lightly tint the result toward the background's hue (default false)
- Returns:
- a Color meeting the contrast target, or the best available if the target cannot be met
- See Also:
-
brighten
Returns a brighter, more vivid version of the given color by boosting both chroma (color intensity) and lightness together. This produces an "intensified" highlight rather than a washed-out tint (aslighten()alone would) or a hue shift without luminance change (assaturate()alone would).A typical use is hover highlighting in charts: the highlighted color should look like a more vibrant version of the base color rather than a lighter or pinker variant.
The
amountcontrols both axes: lightness receives the full amount while chroma receives half, keeping the color recognizable at typical hover percentages (25–40). For independent control useadjust()directly.- Parameters:
color- any valid CSS color string or structured color objectamount- percentage to brighten, 0-100- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
brighten
Returns a brighter, more vivid version of the given color by boosting both chroma (color intensity) and lightness together. This produces an "intensified" highlight rather than a washed-out tint (aslighten()alone would) or a hue shift without luminance change (assaturate()alone would).A typical use is hover highlighting in charts: the highlighted color should look like a more vibrant version of the base color rather than a lighter or pinker variant.
The
amountcontrols both axes: lightness receives the full amount while chroma receives half, keeping the color recognizable at typical hover percentages (25–40). For independent control useadjust()directly.- Parameters:
color- any valid CSS color string or structured color objectamount- percentage to brighten, 0-100outputFormat- output format; defaults to the detected format of the input color (hex for named colors)- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
complement
Returns the complementary color - the hue on the opposite side of the color wheel (rotated by 180 degrees). Equivalent toadjust(color, {h: 180}).Complementary pairs produce maximum hue contrast and are commonly used for accents, call-to-action elements, or alert states against a primary brand color. The oklch hue wheel: red ~30, yellow ~90, green ~145, cyan ~195, blue ~265, purple ~310. Other useful rotations via
adjust(): +120/-120 for triadic accents, +90/-90 for square-scheme accents.- Parameters:
color- any valid CSS color string or structured color object- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
complement
Returns the complementary color - the hue on the opposite side of the color wheel (rotated by 180 degrees). Equivalent toadjust(color, {h: 180}).Complementary pairs produce maximum hue contrast and are commonly used for accents, call-to-action elements, or alert states against a primary brand color. The oklch hue wheel: red ~30, yellow ~90, green ~145, cyan ~195, blue ~265, purple ~310. Other useful rotations via
adjust(): +120/-120 for triadic accents, +90/-90 for square-scheme accents.- Parameters:
color- any valid CSS color string or structured color object- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
complement
Returns the complementary color - the hue on the opposite side of the color wheel (rotated by 180 degrees). Equivalent toadjust(color, {h: 180}).Complementary pairs produce maximum hue contrast and are commonly used for accents, call-to-action elements, or alert states against a primary brand color. The oklch hue wheel: red ~30, yellow ~90, green ~145, cyan ~195, blue ~265, purple ~310. Other useful rotations via
adjust(): +120/-120 for triadic accents, +90/-90 for square-scheme accents.- Parameters:
color- any valid CSS color string or structured color objectoutputFormat- output format; defaults to the detected format of the input color (hex for named colors)- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
complement
Returns the complementary color - the hue on the opposite side of the color wheel (rotated by 180 degrees). Equivalent toadjust(color, {h: 180}).Complementary pairs produce maximum hue contrast and are commonly used for accents, call-to-action elements, or alert states against a primary brand color. The oklch hue wheel: red ~30, yellow ~90, green ~145, cyan ~195, blue ~265, purple ~310. Other useful rotations via
adjust(): +120/-120 for triadic accents, +90/-90 for square-scheme accents.- Parameters:
color- any valid CSS color string or structured color objectoutputFormat- output format; defaults to the detected format of the input color (hex for named colors)- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
darken
Returns a darker version of the given color. Equivalent toadjust(color, {lightness: -amount}).The
amountis a percentage (0-100) indicating how far to move toward black: 0 returns the original color, 100 returns black. Intermediate values move proportionally -darken(color, 20)always looks like "20% darker" regardless of the starting lightness.For multi-axis adjustments, use
adjust()directly.- Parameters:
color- any valid CSS color string or structured color objectamount- percentage to darken, 0-100- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
darken
Returns a darker version of the given color. Equivalent toadjust(color, {lightness: -amount}).The
amountis a percentage (0-100) indicating how far to move toward black: 0 returns the original color, 100 returns black. Intermediate values move proportionally -darken(color, 20)always looks like "20% darker" regardless of the starting lightness.For multi-axis adjustments, use
adjust()directly.- Parameters:
color- any valid CSS color string or structured color objectamount- percentage to darken, 0-100outputFormat- output format; defaults to the detected format of the input color (hex for named colors)- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
desaturate
Returns a more muted version of the given color by reducing its chroma (color intensity). Equivalent toadjust(color, {saturation: -amount}).The
amountis a percentage (0-100) of chroma to remove: 0 returns the original color, 100 returns a pure gray at the same lightness.For multi-axis adjustments, use
adjust()directly.- Parameters:
color- any valid CSS color string or structured color objectamount- percentage to desaturate, 0-100- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
desaturate
Returns a more muted version of the given color by reducing its chroma (color intensity). Equivalent toadjust(color, {saturation: -amount}).The
amountis a percentage (0-100) of chroma to remove: 0 returns the original color, 100 returns a pure gray at the same lightness.For multi-axis adjustments, use
adjust()directly.- Parameters:
color- any valid CSS color string or structured color objectamount- percentage to desaturate, 0-100outputFormat- output format; defaults to the detected format of the input color (hex for named colors)- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
describeRelationship
Computes the perceptual relationship between two colors in oklch space and returns a structured description. This is the analytical inverse of color manipulation: given a base and a derived color, it tells you what oklch adjustments were applied.For example, a skin has an accent color
#3B82F6and a hand-picked hover color#6BA3F8. To find out what the relationship actually is (so it can be expressed as a formula rather than a second hard-coded hex value):The returned object contains:
- type - a simplified classification:
"lighten","darken","saturate","desaturate","spin","adjust"(multiple significant changes), or"identical" - L - oklch lightness delta (positive = lighter, 0-1 scale)
- C - oklch chroma delta (positive = more saturated)
- h - oklch hue delta in degrees (shortest-arc rotation, -180 to +180)
The type classification uses perceptual thresholds: L changes > 0.01, C changes > 0.005, and hue changes > 2 degrees are considered significant. When exactly one dimension changes significantly, the type reflects that dimension. When multiple dimensions change, the type is
"adjust".- Parameters:
baseColor- the origin/base colorderivedColor- the derived/transformed color- Returns:
- relationship descriptor with type, L, C, h properties
- See Also:
- type - a simplified classification:
-
dim
Returns a dimmer, less vivid version of the given color — the inverse ofbrighten(). Reduces both chroma and lightness together, producing a muted, subdued appearance.- Parameters:
color- any valid CSS color string or structured color objectamount- percentage to dim, 0-100- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
dim
Returns a dimmer, less vivid version of the given color — the inverse ofbrighten(). Reduces both chroma and lightness together, producing a muted, subdued appearance.- Parameters:
color- any valid CSS color string or structured color objectamount- percentage to dim, 0-100outputFormat- output format; defaults to the detected format of the input color (hex for named colors)- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
generateCSS
Converts an oklch relationship descriptor (as returned bydescribeRelationship()orparseRelationship()) into a CSS Relative Color Syntax expression. The generated expression uses oklch as the color space, ensuring perceptually uniform transforms.For example, to define a hover color that is always 10% lighter than the theme's accent, regardless of what the accent color actually is:
The
originparameter is the CSS expression to use as the RCS origin - typically avar()reference like"var(--isc-accent)", but can also be a literal color like"#3B82F6".- Parameters:
origin- the CSS origin expression for the RCS - typically avar()reference or a literal colorrelationship- an object with oklch deltas:L(lightness),C(chroma), and/orh(hue). Properties that are zero, null, or omitted produce identity channel passes. Accepts the output of bothdescribeRelationship()andparseRelationship()- Returns:
- a CSS oklch RCS expression
- See Also:
-
getAlpha
Returns the alpha (opacity) component of the given color as a float from 0.0 (fully transparent) to 1.0 (fully opaque). Returns null if the color is not valid.Accepts any valid CSS color string or structured color object. Fully opaque colors that lack an explicit alpha component return 1.0. The keyword
"transparent"returns 0.0.- Parameters:
color- any valid CSS color string or structured color object- Returns:
- alpha component (0.0 - 1.0), or null if invalid
-
getAlpha
Returns the alpha (opacity) component of the given color as a float from 0.0 (fully transparent) to 1.0 (fully opaque). Returns null if the color is not valid.Accepts any valid CSS color string or structured color object. Fully opaque colors that lack an explicit alpha component return 1.0. The keyword
"transparent"returns 0.0.- Parameters:
color- any valid CSS color string or structured color object- Returns:
- alpha component (0.0 - 1.0), or null if invalid
-
getColor
Parses any valid CSS color into a structuredColorobject with RGB, HSL, and oklch properties pre-computed, plus convenience methods for manipulation.Accepts any CSS color string (
#hex,rgb(),hsl(),oklch(), named colors) or a structured component object in any supported color space:{r, g, b},{h, s, l}, or{L, C, h}.Also accepts CSS Relative Color Syntax (RCS) expressions with literal color origins, such as
rgb(from #3B82F6 calc(r - 0.1) g b),hsl(from #47a7e3 h s calc(l + 20)), oroklch(from #3B82F6 calc(l + 0.15) c h). The origin can be any parseable color string - hex, named, or a nested function call. Channel keywords use CSS-native ranges: RGB channels are 0-1 sRGB fractions (not 0-255), HSL s/l are 0-100, oklch L is 0-1. The origin is resolved, the channel adjustments (bare keywords,calc(),max(),min()) are evaluated, and the result is returned as a fully resolved Color.Expressions containing
var()references orcolor-mix()are automatically resolved through the browser's CSS engine (viaresolveCSS()). This requires DOM access - on the server, such expressions return an invalid Color.Always returns a
Colorobject. If the input cannot be parsed, the returned object will haveisValid()returning false (properties default to black). If the input is already aColor, a new Color with the same values is returned. -
getColor
Parses any valid CSS color into a structuredColorobject with RGB, HSL, and oklch properties pre-computed, plus convenience methods for manipulation.Accepts any CSS color string (
#hex,rgb(),hsl(),oklch(), named colors) or a structured component object in any supported color space:{r, g, b},{h, s, l}, or{L, C, h}.Also accepts CSS Relative Color Syntax (RCS) expressions with literal color origins, such as
rgb(from #3B82F6 calc(r - 0.1) g b),hsl(from #47a7e3 h s calc(l + 20)), oroklch(from #3B82F6 calc(l + 0.15) c h). The origin can be any parseable color string - hex, named, or a nested function call. Channel keywords use CSS-native ranges: RGB channels are 0-1 sRGB fractions (not 0-255), HSL s/l are 0-100, oklch L is 0-1. The origin is resolved, the channel adjustments (bare keywords,calc(),max(),min()) are evaluated, and the result is returned as a fully resolved Color.Expressions containing
var()references orcolor-mix()are automatically resolved through the browser's CSS engine (viaresolveCSS()). This requires DOM access - on the server, such expressions return an invalid Color.Always returns a
Colorobject. If the input cannot be parsed, the returned object will haveisValid()returning false (properties default to black). If the input is already aColor, a new Color with the same values is returned. -
getColor
Parses any valid CSS color into a structuredColorobject with RGB, HSL, and oklch properties pre-computed, plus convenience methods for manipulation.Accepts any CSS color string (
#hex,rgb(),hsl(),oklch(), named colors) or a structured component object in any supported color space:{r, g, b},{h, s, l}, or{L, C, h}.Also accepts CSS Relative Color Syntax (RCS) expressions with literal color origins, such as
rgb(from #3B82F6 calc(r - 0.1) g b),hsl(from #47a7e3 h s calc(l + 20)), oroklch(from #3B82F6 calc(l + 0.15) c h). The origin can be any parseable color string - hex, named, or a nested function call. Channel keywords use CSS-native ranges: RGB channels are 0-1 sRGB fractions (not 0-255), HSL s/l are 0-100, oklch L is 0-1. The origin is resolved, the channel adjustments (bare keywords,calc(),max(),min()) are evaluated, and the result is returned as a fully resolved Color.Expressions containing
var()references orcolor-mix()are automatically resolved through the browser's CSS engine (viaresolveCSS()). This requires DOM access - on the server, such expressions return an invalid Color.Always returns a
Colorobject. If the input cannot be parsed, the returned object will haveisValid()returning false (properties default to black). If the input is already aColor, a new Color with the same values is returned. -
getFormat
Returns theColorFormatof the given color string, or null if the value is not a valid color. For named colors (e.g. "red") and "transparent", the format is reported as"hex"since the canonical representation is hexadecimal.- Parameters:
color- a CSS color string- Returns:
- the detected format, or null if invalid
-
getString
Converts any valid CSS color to a string in the specified format. Accepts a CSS color string or a structured color object (as returned bygetColor()). Returns null if the input is not a valid color or the format is unrecognized.Supported target formats:
"hex"- "#RRGGBB" when opaque, "#RRGGBBAA" when semi-transparent"rgb"- "rgb(R, G, B)" when opaque, "rgba(R, G, B, A)" when semi-transparent"hsl"- "hsl(H, S%, L%)" when opaque, "hsla(H, S%, L%, A)" when semi-transparent"oklch"- "oklch(L% C h)" when opaque, "oklch(L% C h / A)" when semi-transparent
- Parameters:
color- any valid CSS color string, or a structured color object with {r,g,b}, {h,s,l}, or {L,C,h} keysformat- target format: "hex", "rgb", "hsl", or "oklch"- Returns:
- CSS color string in the target format, or null
-
getValues
Returns a plain object with color component values in the requested format. UnlikegetColor(), which returns a fullColorobject with methods and properties in all color spaces, this returns only the numeric components for the requested format - useful when you need raw values for computation without the overhead of a full Color, or when passing components to external APIs.Supported formats and their returned keys:
"rgb"-{r, g, b, alpha}(0-255 integers, alpha 0-1)"hsl"-{h, s, l, alpha}(h: 0-360 degrees, s/l: 0-100 percent, alpha 0-1)"oklch"-{L, C, h, alpha}(L: 0-1 lightness, C: 0+ chroma, h: 0-360 degrees, alpha 0-1)
- Parameters:
color- any valid CSS color string orColorformat- target format: "rgb", "hsl", or "oklch"- Returns:
- plain object with numeric component keys, or null if invalid
- See Also:
-
isColor
Returns true if the given value is a valid CSS color specification. Accepts any format: hex (#RGB, #RRGGBB, #RRGGBBAA), rgb(), rgba(), hsl(), hsla(), oklch(), named colors, "transparent", CSS Relative Color Syntax expressions, andvar()orcolor-mix()expressions (resolved via the browser's CSS engine when a DOM is available; returns false server-side).If
formatis specified, the value must be parseable in that particular format (or be "transparent", which is always valid).- Parameters:
color- value to test- Returns:
- true if the value represents a valid color
-
isColor
Returns true if the given value is a valid CSS color specification. Accepts any format: hex (#RGB, #RRGGBB, #RRGGBBAA), rgb(), rgba(), hsl(), hsla(), oklch(), named colors, "transparent", CSS Relative Color Syntax expressions, andvar()orcolor-mix()expressions (resolved via the browser's CSS engine when a DOM is available; returns false server-side).If
formatis specified, the value must be parseable in that particular format (or be "transparent", which is always valid).- Parameters:
color- value to test- Returns:
- true if the value represents a valid color
-
isColor
Returns true if the given value is a valid CSS color specification. Accepts any format: hex (#RGB, #RRGGBB, #RRGGBBAA), rgb(), rgba(), hsl(), hsla(), oklch(), named colors, "transparent", CSS Relative Color Syntax expressions, andvar()orcolor-mix()expressions (resolved via the browser's CSS engine when a DOM is available; returns false server-side).If
formatis specified, the value must be parseable in that particular format (or be "transparent", which is always valid).- Parameters:
color- value to test- Returns:
- true if the value represents a valid color
-
isColor
Returns true if the given value is a valid CSS color specification. Accepts any format: hex (#RGB, #RRGGBB, #RRGGBBAA), rgb(), rgba(), hsl(), hsla(), oklch(), named colors, "transparent", CSS Relative Color Syntax expressions, andvar()orcolor-mix()expressions (resolved via the browser's CSS engine when a DOM is available; returns false server-side).If
formatis specified, the value must be parseable in that particular format (or be "transparent", which is always valid).- Parameters:
color- value to testformat- if specified, require this format- Returns:
- true if the value represents a valid color
-
isColor
Returns true if the given value is a valid CSS color specification. Accepts any format: hex (#RGB, #RRGGBB, #RRGGBBAA), rgb(), rgba(), hsl(), hsla(), oklch(), named colors, "transparent", CSS Relative Color Syntax expressions, andvar()orcolor-mix()expressions (resolved via the browser's CSS engine when a DOM is available; returns false server-side).If
formatis specified, the value must be parseable in that particular format (or be "transparent", which is always valid).- Parameters:
color- value to testformat- if specified, require this format- Returns:
- true if the value represents a valid color
-
isColor
Returns true if the given value is a valid CSS color specification. Accepts any format: hex (#RGB, #RRGGBB, #RRGGBBAA), rgb(), rgba(), hsl(), hsla(), oklch(), named colors, "transparent", CSS Relative Color Syntax expressions, andvar()orcolor-mix()expressions (resolved via the browser's CSS engine when a DOM is available; returns false server-side).If
formatis specified, the value must be parseable in that particular format (or be "transparent", which is always valid).- Parameters:
color- value to testformat- if specified, require this format- Returns:
- true if the value represents a valid color
-
isDark
Returns true if the given color is perceptually dark (i.e. would need light foreground text for readability), false if it is light. Uses oklch lightness, which is perceptually uniform - unlike RGB or HSL brightness, a threshold of 0.6 consistently separates light from dark colors across hues. Use!isDark(color)to test for lightness.Returns null if the color is not valid.
- Parameters:
color- any valid CSS color string or structured color object- Returns:
- true if perceptually dark, false if light, null if invalid
-
isDark
Returns true if the given color is perceptually dark (i.e. would need light foreground text for readability), false if it is light. Uses oklch lightness, which is perceptually uniform - unlike RGB or HSL brightness, a threshold of 0.6 consistently separates light from dark colors across hues. Use!isDark(color)to test for lightness.Returns null if the color is not valid.
- Parameters:
color- any valid CSS color string or structured color object- Returns:
- true if perceptually dark, false if light, null if invalid
-
lighten
Returns a lighter version of the given color. Equivalent toadjust(color, {lightness: amount}).The
amountis a percentage (0-100) indicating how far to move toward white: 0 returns the original color, 100 returns white. Intermediate values move proportionally -lighten(color, 20)on a dark color produces a bigger absolute lightness change than on an already-light color, but both look like "20% lighter" perceptually.For multi-axis adjustments (e.g. lighten and desaturate together), use
adjust()directly.- Parameters:
color- any valid CSS color string or structured color objectamount- percentage to lighten, 0-100- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
lighten
Returns a lighter version of the given color. Equivalent toadjust(color, {lightness: amount}).The
amountis a percentage (0-100) indicating how far to move toward white: 0 returns the original color, 100 returns white. Intermediate values move proportionally -lighten(color, 20)on a dark color produces a bigger absolute lightness change than on an already-light color, but both look like "20% lighter" perceptually.For multi-axis adjustments (e.g. lighten and desaturate together), use
adjust()directly.- Parameters:
color- any valid CSS color string or structured color objectamount- percentage to lighten, 0-100outputFormat- output format; defaults to the detected format of the input color (hex for named colors)- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
mostReadable
Returns the color fromcandidatesthat has the highest contrast againstbackground. Useful for choosing a text color that will be readable on a given background - typically called with["#ffffff", "#000000"]as candidates.- Parameters:
background- the background color to test againstcandidates- list of candidate foreground colors- Returns:
- the candidate with the highest contrast ratio, or null if inputs invalid
-
palette
Generates a tonal ramp - an ordered series of colors at different lightness levels sharing the same hue. In color theory, lighter variants of a color are called tints (mixed toward white) and darker variants are called shades (mixed toward black); this method produces both in a single ramp. This is the core operation for theme generation: one brand color in, a full light-to-dark palette out.At its simplest,
palette("#3366CC", 7)produces 7 stops from dark to light - usable directly as skin backgrounds, hover fills, text colors, and borders. With no options, it uses sensible defaults: a natural chroma curve (vivid in the mid-range, muted at extremes) and a subtle hue shift for a professional, non-flat appearance.For a plain lightness scale with no chroma or hue variation, pass
{ chromaCurve: "constant", hueShift: 0 }.All returned colors are guaranteed to be within the sRGB gamut (via automatic chroma reduction at the extremes). The seed color's own lightness determines where in the ramp it falls - it is not forced to a specific stop index.
- Parameters:
color- the seed color whose hue and chroma define the palette- Returns:
- array of Color objects ordered from darkest to lightest
- See Also:
-
palette
Generates a tonal ramp - an ordered series of colors at different lightness levels sharing the same hue. In color theory, lighter variants of a color are called tints (mixed toward white) and darker variants are called shades (mixed toward black); this method produces both in a single ramp. This is the core operation for theme generation: one brand color in, a full light-to-dark palette out.At its simplest,
palette("#3366CC", 7)produces 7 stops from dark to light - usable directly as skin backgrounds, hover fills, text colors, and borders. With no options, it uses sensible defaults: a natural chroma curve (vivid in the mid-range, muted at extremes) and a subtle hue shift for a professional, non-flat appearance.For a plain lightness scale with no chroma or hue variation, pass
{ chromaCurve: "constant", hueShift: 0 }.All returned colors are guaranteed to be within the sRGB gamut (via automatic chroma reduction at the extremes). The seed color's own lightness determines where in the ramp it falls - it is not forced to a specific stop index.
- Parameters:
color- the seed color whose hue and chroma define the palette- Returns:
- array of Color objects ordered from darkest to lightest
- See Also:
-
palette
Seepalette() -
palette
Seepalette() -
palette
Generates a tonal ramp - an ordered series of colors at different lightness levels sharing the same hue. In color theory, lighter variants of a color are called tints (mixed toward white) and darker variants are called shades (mixed toward black); this method produces both in a single ramp. This is the core operation for theme generation: one brand color in, a full light-to-dark palette out.At its simplest,
palette("#3366CC", 7)produces 7 stops from dark to light - usable directly as skin backgrounds, hover fills, text colors, and borders. With no options, it uses sensible defaults: a natural chroma curve (vivid in the mid-range, muted at extremes) and a subtle hue shift for a professional, non-flat appearance.For a plain lightness scale with no chroma or hue variation, pass
{ chromaCurve: "constant", hueShift: 0 }.All returned colors are guaranteed to be within the sRGB gamut (via automatic chroma reduction at the extremes). The seed color's own lightness determines where in the ramp it falls - it is not forced to a specific stop index.
- Parameters:
color- the seed color whose hue and chroma define the palettesteps- number of stops to generate (default 11)options- optional settings:lightnessRange- two-element array of oklch L values for the darkest and lightest stops (default[0.15, 0.97])chromaCurve-"natural"(default) tapers chroma toward extremes using a cosine curve;"constant"uses the seed's chroma for all stops;"peaked"pushes maximum chroma to a configurable lightnesshueShift- degrees of hue rotation across the full lightness range (default ~4; set to 0 to disable). Positive values shift lighter stops toward warmer hues.
- Returns:
- array of Color objects ordered from darkest to lightest
- See Also:
-
palette
Generates a tonal ramp - an ordered series of colors at different lightness levels sharing the same hue. In color theory, lighter variants of a color are called tints (mixed toward white) and darker variants are called shades (mixed toward black); this method produces both in a single ramp. This is the core operation for theme generation: one brand color in, a full light-to-dark palette out.At its simplest,
palette("#3366CC", 7)produces 7 stops from dark to light - usable directly as skin backgrounds, hover fills, text colors, and borders. With no options, it uses sensible defaults: a natural chroma curve (vivid in the mid-range, muted at extremes) and a subtle hue shift for a professional, non-flat appearance.For a plain lightness scale with no chroma or hue variation, pass
{ chromaCurve: "constant", hueShift: 0 }.All returned colors are guaranteed to be within the sRGB gamut (via automatic chroma reduction at the extremes). The seed color's own lightness determines where in the ramp it falls - it is not forced to a specific stop index.
- Parameters:
color- the seed color whose hue and chroma define the palettesteps- number of stops to generate (default 11)options- optional settings:lightnessRange- two-element array of oklch L values for the darkest and lightest stops (default[0.15, 0.97])chromaCurve-"natural"(default) tapers chroma toward extremes using a cosine curve;"constant"uses the seed's chroma for all stops;"peaked"pushes maximum chroma to a configurable lightnesshueShift- degrees of hue rotation across the full lightness range (default ~4; set to 0 to disable). Positive values shift lighter stops toward warmer hues.
- Returns:
- array of Color objects ordered from darkest to lightest
- See Also:
-
parseRelationship
Extracts structural information from a CSS Relative Color Syntax (RCS) expression - the origin reference, color space, and per-channel modifications - without evaluating it. This is pure string parsing: no DOM access and no color resolution. It works with any origin, includingvar()references (whichgetColor()would resolve via the DOM - parseRelationship preserves the raw reference for structural inspection).For example, a skin config stores
oklch(from var(--isc-accent) calc(l + 0.15) c h)for a hover color.parseRelationship()extracts the structure so you can see what is being derived from what, without needing to resolve the colors:The returned object describes the expression's structure:
- origin - the raw origin string as it appears in the expression (e.g.
"var(--isc-accent)","#ff0000"). If the origin is avar()reference, the caller must useresolveCSS()to resolve it to an actual color -getColor()cannot resolvevar()references. - space - the color space:
"rgb","hsl", or"oklch" - deltas - an object mapping channel names to their additive delta (only channels that differ from identity). For example,
{l: 0.15}means lightness is shifted by +0.15 while other channels pass through unchanged. Channels with complex expressions (multiplication, clamping via max/min) are omitted from deltas but present in rawChannels. - rawChannels - an array of three raw channel expression strings in CSS order, useful for complex expressions that cannot be reduced to a simple delta
- alpha - the alpha value (1.0 if not specified)
Returns null if the expression is not valid RCS syntax (plain hex, rgb(), named colors, and
color-mix()are not RCS and will return null).- Parameters:
rcsExpr- a CSS RCS expression, e.g."oklch(from var(--x) calc(l + 0.15) c h)"- Returns:
- structured descriptor, or null if not valid RCS
- See Also:
- origin - the raw origin string as it appears in the expression (e.g.
-
resolveCSS
Resolves any CSS color expression to a flatColorby evaluating it through the browser's CSS engine. Handlesvar()references,color-mix(), and any other CSS color constructs supported by the current browser.getColor()automatically delegates to this method for expressions containingvar()orcolor-mix(), so most callers never need to callresolveCSS()directly. The main reason to use it explicitly is when you need to pass anelementcontext for inherited CSS custom properties:Internally, a scratch DOM element's
colorstyle is set to the expression andgetComputedStyle()reads back the browser-resolved value. If anelementis provided, the scratch element is temporarily appended as its child, allowing inherited CSS custom properties to resolve correctly.Returns an invalid Color (with
isValid()false) if the expression is not a valid CSS color in the current browser, or if no DOM is available (e.g. server-side).- Parameters:
expr- any CSS color expression - hex, rgb(), hsl(), oklch(), color-mix(), var() references, RCS expressions, or any combination the browser supports- Returns:
- resolved Color object, or an invalid Color if the expression could not be resolved
- See Also:
-
resolveCSS
Resolves any CSS color expression to a flatColorby evaluating it through the browser's CSS engine. Handlesvar()references,color-mix(), and any other CSS color constructs supported by the current browser.getColor()automatically delegates to this method for expressions containingvar()orcolor-mix(), so most callers never need to callresolveCSS()directly. The main reason to use it explicitly is when you need to pass anelementcontext for inherited CSS custom properties:Internally, a scratch DOM element's
colorstyle is set to the expression andgetComputedStyle()reads back the browser-resolved value. If anelementis provided, the scratch element is temporarily appended as its child, allowing inherited CSS custom properties to resolve correctly.Returns an invalid Color (with
isValid()false) if the expression is not a valid CSS color in the current browser, or if no DOM is available (e.g. server-side).- Parameters:
expr- any CSS color expression - hex, rgb(), hsl(), oklch(), color-mix(), var() references, RCS expressions, or any combination the browser supportselement- optional DOM element to use as the resolution context; if provided, CSS custom properties inherited by this element will be available forvar()resolution- Returns:
- resolved Color object, or an invalid Color if the expression could not be resolved
- See Also:
-
saturate
Returns a more vivid version of the given color by increasing its chroma (color intensity). Equivalent toadjust(color, {saturation: amount}).The
amountis a percentage (0-100) of additional chroma to add, scaled relative to a practical maximum. A gray color (chroma 0) saturated by 50 produces a clearly visible color; 100 gives full vivid saturation.For multi-axis adjustments, use
adjust()directly.- Parameters:
color- any valid CSS color string or structured color objectamount- percentage to saturate, 0-100- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
saturate
Returns a more vivid version of the given color by increasing its chroma (color intensity). Equivalent toadjust(color, {saturation: amount}).The
amountis a percentage (0-100) of additional chroma to add, scaled relative to a practical maximum. A gray color (chroma 0) saturated by 50 produces a clearly visible color; 100 gives full vivid saturation.For multi-axis adjustments, use
adjust()directly.- Parameters:
color- any valid CSS color string or structured color objectamount- percentage to saturate, 0-100outputFormat- output format; defaults to the detected format of the input color (hex for named colors)- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
scheme
Generates a set of harmonious seed colors from a single primary. Unlike the lower-level harmony methods (triad(),tetrad(), etc.) which return raw CSS strings at fixed hue rotations,scheme()returns a structured object with semantic key names and applies chroma/lightness adjustments so that secondary and tertiary colors feel subordinate to the primary - a requirement for professional UI themes.The returned object always contains a
primaryColor plus one or more supporting keys depending on the scheme type. It also includes auto-generatedneutral(very low chroma at the primary's hue) anderror(red variant) keys. Each seed can be passed topalette()to generate a full tonal ramp.- Parameters:
color- the primary seed color- Returns:
- a map with
primary,secondary,tertiary(where applicable),neutral, anderrorkeys, each aColorobject - See Also:
-
scheme
Generates a set of harmonious seed colors from a single primary. Unlike the lower-level harmony methods (triad(),tetrad(), etc.) which return raw CSS strings at fixed hue rotations,scheme()returns a structured object with semantic key names and applies chroma/lightness adjustments so that secondary and tertiary colors feel subordinate to the primary - a requirement for professional UI themes.The returned object always contains a
primaryColor plus one or more supporting keys depending on the scheme type. It also includes auto-generatedneutral(very low chroma at the primary's hue) anderror(red variant) keys. Each seed can be passed topalette()to generate a full tonal ramp.- Parameters:
color- the primary seed color- Returns:
- a map with
primary,secondary,tertiary(where applicable),neutral, anderrorkeys, each aColorobject - See Also:
-
scheme
Generates a set of harmonious seed colors from a single primary. Unlike the lower-level harmony methods (triad(),tetrad(), etc.) which return raw CSS strings at fixed hue rotations,scheme()returns a structured object with semantic key names and applies chroma/lightness adjustments so that secondary and tertiary colors feel subordinate to the primary - a requirement for professional UI themes.The returned object always contains a
primaryColor plus one or more supporting keys depending on the scheme type. It also includes auto-generatedneutral(very low chroma at the primary's hue) anderror(red variant) keys. Each seed can be passed topalette()to generate a full tonal ramp.- Parameters:
color- the primary seed colortype- scheme type:"complementary","analogous","triadic","split-complementary"(default),"tetradic", or"monochromatic"- Returns:
- a map with
primary,secondary,tertiary(where applicable),neutral, anderrorkeys, each aColorobject - See Also:
-
scheme
Generates a set of harmonious seed colors from a single primary. Unlike the lower-level harmony methods (triad(),tetrad(), etc.) which return raw CSS strings at fixed hue rotations,scheme()returns a structured object with semantic key names and applies chroma/lightness adjustments so that secondary and tertiary colors feel subordinate to the primary - a requirement for professional UI themes.The returned object always contains a
primaryColor plus one or more supporting keys depending on the scheme type. It also includes auto-generatedneutral(very low chroma at the primary's hue) anderror(red variant) keys. Each seed can be passed topalette()to generate a full tonal ramp.- Parameters:
color- the primary seed colortype- scheme type:"complementary","analogous","triadic","split-complementary"(default),"tetradic", or"monochromatic"- Returns:
- a map with
primary,secondary,tertiary(where applicable),neutral, anderrorkeys, each aColorobject - See Also:
-
setAlpha
Returns a new color string with the alpha (opacity) component replaced. The output format matches the input format when possible; for named colors, hex is used.Useful for deriving semi-transparent variants of a color without converting it to a different format.
- Parameters:
color- any valid CSS color string or structured color objectalpha- new alpha value, 0.0 (transparent) to 1.0 (opaque)- Returns:
- CSS color string with the new alpha, or null if invalid
-
setAlpha
Returns a new color string with the alpha (opacity) component replaced. The output format matches the input format when possible; for named colors, hex is used.Useful for deriving semi-transparent variants of a color without converting it to a different format.
- Parameters:
color- any valid CSS color string or structured color objectalpha- new alpha value, 0.0 (transparent) to 1.0 (opaque)outputFormat- optional output format; defaults to the detected format of the input color- Returns:
- CSS color string with the new alpha, or null if invalid
-
spin
Rotates the hue of a color by the given number of degrees (in oklch space). Positive values rotate clockwise, negative counter-clockwise. This is a convenience wrapper aroundadjust(color, {hue: degrees}).- Parameters:
color- any valid CSS color string or structured color objectdegrees- signed rotation in degrees (e.g. 90, -45, 180)- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
spin
Rotates the hue of a color by the given number of degrees (in oklch space). Positive values rotate clockwise, negative counter-clockwise. This is a convenience wrapper aroundadjust(color, {hue: degrees}).- Parameters:
color- any valid CSS color string or structured color objectdegrees- signed rotation in degrees (e.g. 90, -45, 180)outputFormat- output format; defaults to the detected format of the input color (hex for named colors)- Returns:
- CSS color string, or null if the input is not a valid color
- See Also:
-
splitComplement
Returns three colors: the original plus two split-complement accents (hue +150 and +210 degrees - flanking the complement rather than hitting it directly). Produces a more nuanced palette than a straight complementary pair.- Parameters:
color- base color- Returns:
- three CSS color strings
-
splitComplement
Returns three colors: the original plus two split-complement accents (hue +150 and +210 degrees - flanking the complement rather than hitting it directly). Produces a more nuanced palette than a straight complementary pair.- Parameters:
color- base color- Returns:
- three CSS color strings
-
splitComplement
Returns three colors: the original plus two split-complement accents (hue +150 and +210 degrees - flanking the complement rather than hitting it directly). Produces a more nuanced palette than a straight complementary pair.- Parameters:
color- base coloroutputFormat- output format; defaults to input format- Returns:
- three CSS color strings
-
splitComplement
Returns three colors: the original plus two split-complement accents (hue +150 and +210 degrees - flanking the complement rather than hitting it directly). Produces a more nuanced palette than a straight complementary pair.- Parameters:
color- base coloroutputFormat- output format; defaults to input format- Returns:
- three CSS color strings
-
tetrad
Returns four colors with hues spaced 90 degrees apart (square scheme). The first element is the original color, then +90, +180, +270 degrees.- Parameters:
color- base color- Returns:
- four CSS color strings
-
tetrad
Returns four colors with hues spaced 90 degrees apart (square scheme). The first element is the original color, then +90, +180, +270 degrees.- Parameters:
color- base color- Returns:
- four CSS color strings
-
tetrad
Returns four colors with hues spaced 90 degrees apart (square scheme). The first element is the original color, then +90, +180, +270 degrees.- Parameters:
color- base coloroutputFormat- output format; defaults to input format- Returns:
- four CSS color strings
-
tetrad
Returns four colors with hues spaced 90 degrees apart (square scheme). The first element is the original color, then +90, +180, +270 degrees.- Parameters:
color- base coloroutputFormat- output format; defaults to input format- Returns:
- four CSS color strings
-
triad
Returns the three triadic colors (hues spaced 120 degrees apart). The first element is the original color, the second is +120 degrees, the third is +240 degrees.- Parameters:
color- base color- Returns:
- three CSS color strings
-
triad
Returns the three triadic colors (hues spaced 120 degrees apart). The first element is the original color, the second is +120 degrees, the third is +240 degrees.- Parameters:
color- base color- Returns:
- three CSS color strings
-
triad
Returns the three triadic colors (hues spaced 120 degrees apart). The first element is the original color, the second is +120 degrees, the third is +240 degrees.- Parameters:
color- base coloroutputFormat- output format; defaults to input format- Returns:
- three CSS color strings
-
triad
Returns the three triadic colors (hues spaced 120 degrees apart). The first element is the original color, the second is +120 degrees, the third is +240 degrees.- Parameters:
color- base coloroutputFormat- output format; defaults to input format- Returns:
- three CSS color strings
-
colorScale
Generates an array of evenly-spaced colors between two endpoints, interpolated in oklch by default. Use the 5-parameter overload to choose a different interpolation space.- Parameters:
color1- start colorcolor2- end colorsteps- number of colors to produce (minimum 2)- Returns:
- CSS color strings, or null if either input is invalid
-
colorScale
Generates an array of evenly-spaced colors between two endpoints, interpolated in the oklch color space for perceptual uniformity.- Parameters:
color1- start colorcolor2- end colorsteps- number of colors to produce (minimum 2)format- output format; defaults to the detected format ofcolor1- Returns:
- CSS color strings, or null if either input is invalid
-
colorScale
Generates an array of evenly-spaced colors between twoColorendpoints, interpolated in the oklch color space for perceptual uniformity.- Parameters:
color1- start colorcolor2- end colorsteps- number of colors to produce (minimum 2)- Returns:
- CSS color strings, or null if either input is invalid
-
colorScale
Generates an array of evenly-spaced colors between twoColorendpoints, interpolated in the oklch color space for perceptual uniformity.- Parameters:
color1- start colorcolor2- end colorsteps- number of colors to produce (minimum 2)format- output format; defaults to the detected format ofcolor1- Returns:
- CSS color strings, or null if either input is invalid
-
colorScale
public static String[] colorScale(String color1, String color2, int steps, ColorFormat format, ColorFormat space) Generates an array of evenly-spaced colors between two endpoints, interpolated in the specified color space.- Parameters:
color1- start colorcolor2- end colorsteps- number of colors to produce (minimum 2)format- output format; defaults to the detected format ofcolor1space- color space for interpolation: oklch (default), hsl, or rgb/hex (both mean linear RGB)- Returns:
- CSS color strings, or null if either input is invalid
-
colorScale
public static String[] colorScale(Color color1, Color color2, int steps, ColorFormat format, ColorFormat space) Generates an array of evenly-spaced colors between twoColorendpoints, interpolated in the specified color space.- Parameters:
color1- start colorcolor2- end colorsteps- number of colors to produce (minimum 2)format- output format; defaults to the detected format ofcolor1space- color space for interpolation: oklch (default), hsl, or rgb/hex (both mean linear RGB)- Returns:
- CSS color strings, or null if either input is invalid
-
flatten
Returns an opaque color visually equivalent to the given semi-transparent color composited over a background (default white). If already fully opaque, returns unchanged.- Parameters:
color- a semi-transparent color to flatten- Returns:
- opaque CSS color string, or null if invalid
-
flatten
Returns an opaque color visually equivalent to the given semi-transparentColorcomposited over a background (default white). If already fully opaque, returns unchanged.- Parameters:
color- a semi-transparent color to flatten- Returns:
- opaque CSS color string, or null if invalid
-
flatten
Flattens a semi-transparent color against a background.- Parameters:
color- a semi-transparent color to flattenbackground- background to composite against- Returns:
- opaque CSS color string, or null if invalid
-
flatten
Flattens a semi-transparent color against a background, returning the result in the specified format.- Parameters:
color- a semi-transparent color to flattenbackground- background to composite againstoutputFormat- output format; defaults to the detected format of the input color- Returns:
- opaque CSS color string, or null if invalid
-
flatten
Flattens a semi-transparentColoragainst a background.- Parameters:
color- a semi-transparent color to flattenbackground- background to composite against- Returns:
- opaque CSS color string, or null if invalid
-
flatten
Flattens a semi-transparentColoragainst a background, returning the result in the specified format.- Parameters:
color- a semi-transparent color to flattenbackground- background to composite againstoutputFormat- output format; defaults to the detected format of the input color- Returns:
- opaque CSS color string, or null if invalid
-
contrast
Returns the approximate perceptual contrast ratio between two colors, based on oklch lightness. A ratio of at least 4.5 is recommended for WCAG AA, 7.0 for AAA. Returns null if either color is invalid.- Parameters:
color1- first colorcolor2- second color- Returns:
- contrast ratio (>= 1.0), or null
-
contrast
Returns the approximate perceptual contrast ratio between twoColorobjects, based on oklch lightness. A ratio of at least 4.5 is recommended for WCAG AA, 7.0 for AAA. Returns null if either color is invalid.- Parameters:
color1- first colorcolor2- second color- Returns:
- contrast ratio (>= 1.0), or null
-
distance
Returns a number indicating how different two colors look to the human eye. 0 means identical; larger values mean more visible difference. Uses oklab (the Cartesian form of oklch) so that equal numeric distances correspond to equal perceived differences. Returns null if either color is invalid.- Parameters:
color1- first colorcolor2- second color- Returns:
- perceptual distance (>= 0), or null
-
distance
Returns a number indicating how different twoColorobjects look to the human eye. 0 means identical; larger values mean more visible difference. Uses oklab so that equal numeric distances correspond to equal perceived differences. Returns null if either color is invalid.- Parameters:
color1- first colorcolor2- second color- Returns:
- perceptual distance (>= 0), or null
-
equals
Returns true if two color values represent the same color (same R, G, B, and alpha), regardless of input format.- Parameters:
color1- first colorcolor2- second color- Returns:
- true if identical, false otherwise, null if either invalid
-
equals
Returns true if twoColorobjects represent the same color (same R, G, B, and alpha).- Parameters:
color1- first colorcolor2- second color- Returns:
- true if identical, false otherwise, null if either invalid
-
mix
Blends two colors in the oklch color space, producing a single result. Equivalent to callingmix(String, String, Double, ColorFormat)with default ratio (0.5) and default format.- Parameters:
color1- first colorcolor2- second color- Returns:
- CSS color string, or null if either input is invalid
-
mix
Blends two colors in the oklch color space at the given ratio.- Parameters:
color1- first colorcolor2- second colorratio- blend ratio, 0.0 (all color1) to 1.0 (all color2); defaults to 0.5- Returns:
- CSS color string, or null if either input is invalid
-
mix
Blends two colors in the oklch color space at the given ratio, returning the result in the specified format.- Parameters:
color1- first colorcolor2- second colorratio- blend ratio, 0.0 (all color1) to 1.0 (all color2); defaults to 0.5outputFormat- output format; defaults to the detected format ofcolor1- Returns:
- CSS color string, or null if either input is invalid
-
mix
Blends twoColorobjects in the oklch color space. Equivalent to callingmix(Color, Color, Double, ColorFormat)with default ratio (0.5) and default format.- Parameters:
color1- first colorcolor2- second color- Returns:
- CSS color string, or null if either input is invalid
-
mix
Blends twoColorobjects in the oklch color space at the given ratio.- Parameters:
color1- first colorcolor2- second colorratio- blend ratio, 0.0 (all color1) to 1.0 (all color2); defaults to 0.5- Returns:
- CSS color string, or null if either input is invalid
-
mix
Blends twoColorobjects in the oklch color space at the given ratio, returning the result in the specified format.- Parameters:
color1- first colorcolor2- second colorratio- blend ratio, 0.0 (all color1) to 1.0 (all color2); defaults to 0.5outputFormat- output format; defaults to the detected format ofcolor1- Returns:
- CSS color string, or null if either input is invalid
-