/color
Color space conversions (hex, RGB, HSL, OKLCH), WCAG contrast ratios, and tonal palette operations.
Structs#
HSL#
structCylindrical HSL color space: - h: hue angle in degrees (0.0..360.0) - s: saturation (0.0..1.0) - l: lightness (0.0..1.0) - a: alpha (0.0..1.0, default 1.0)
| Field | Type | Default | Constraints / Notes |
|---|---|---|---|
h | Float | — | — |
s | Float | — | — |
l | Float | — | — |
a | Float | — | — |
Oklch#
structPerceptual Oklch color space: - l: perceived lightness (0.0..1.0) - c: chroma (0.0..~0.4) - h: hue angle in degrees (0.0..360.0) - a: alpha (0.0..1.0, default 1.0)
| Field | Type | Default | Constraints / Notes |
|---|---|---|---|
l | Float | — | — |
c | Float | — | — |
h | Float | — | — |
a | Float | — | — |
RGB#
struct3-channel linear or sRGB color (0.0..1.0). Derives `Eq` and `Vec` for full Euclidean vector arithmetic (`+`, `-`, `*`, `/`, `cmul`, `lerp`, `dot`).
| Field | Type | Default | Constraints / Notes |
|---|---|---|---|
r | Float | — | — |
g | Float | — | — |
b | Float | — | — |
RGBA#
struct4-channel sRGB color with alpha (0.0..1.0, default alpha 1.0).
| Field | Type | Default | Constraints / Notes |
|---|---|---|---|
r | Float | — | — |
g | Float | — | — |
b | Float | — | — |
a | Float | — | — |
Functions & symbols#
contrast-ratio#
Computes the WCAG 2.1 contrast ratio (`1.0` to `21.0`) between two colors.
| Parameter | Type | Optional | Description |
|---|---|---|---|
fg | Any | required | Foreground color |
bg | Any | required | Background color |
Any(color/contrast-ratio "#000000" "#ffffff") ; -> 21.0darken#
Decreases perceptual Oklch lightness `l` by `amount`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | Any | required | Base color |
amount | Float | required | Lightness delta in Oklch (0.0..1.0) |
Any(color/darken "#3b82f6" 0.12)desaturate#
Decreases Oklch chroma `c` toward neutral gray.
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | Any | required | Base color |
amount | Float | required | Chroma decrease |
Any(color/desaturate "#3b82f6" 0.05)invert#
Inverts the RGB channels (`1.0 - c`) while keeping alpha unchanged.
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | RGB | RGBA | Oklch | HSL | String | Int | required | Input color struct, CSS color string, or 0xRRGGBB integer |
Any(color/invert "#000000")lighten#
Increases perceptual Oklch lightness `l` by `amount`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | Any | required | Base color |
amount | Float | required | Lightness delta in Oklch (0.0..1.0) |
Any(color/lighten "#3b82f6" 0.12)linear-to-srgb#
Encodes linear-light channel(s) into sRGB gamma.
Any(color/linear-to-srgb 0.214)luminance#
Computes WCAG relative luminance (`0.0` black to `1.0` white).
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | RGB | RGBA | Oklch | HSL | String | Int | required | Input color struct, CSS color string, or 0xRRGGBB integer |
Any(color/luminance "#ffffff") ; -> 1.0mix#
Perceptually interpolates between `c1` and `c2` in Oklch space.
| Parameter | Type | Optional | Description |
|---|---|---|---|
c1 | Any | required | First color |
c2 | Any | required | Second color |
t | Float | optional | Interpolation factor 0.0..1.0 (default 0.5) |
Any(color/mix "#3b82f6" "#ec4899" 0.5)parse#
Parses any CSS color string, integer, or color struct into normalized `RGBA` (`0.0..1.0`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
input | String | Int | RGB | RGBA | Oklch | HSL | required | CSS hex/rgb()/oklch() string, packed int, or color struct |
Any(color/parse "#3b82f6")rotate-hue#
Shifts the Oklch hue angle by `degrees` (modulo 360).
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | Any | required | Base color |
degrees | Float | required | Hue rotation in degrees |
Any(color/rotate-hue "#3b82f6" 180.0)saturate#
Increases Oklch chroma `c` for a more vivid color.
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | Any | required | Base color |
amount | Float | required | Chroma increase |
Any(color/saturate "#3b82f6" 0.05)srgb-to-linear#
Decodes gamma-encoded sRGB channel(s) into linear light.
Any(color/srgb-to-linear 0.5)to-css#
Serializes a color into a standard CSS color function or hex string.
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | Any | required | Color value |
format | KeySymbol | optional | Optional output syntax (:rgb, :hsl, :oklch, :hex) |
Any(color/to-css (color/Oklch 0.7 0.15 240.0) :oklch)to-hex#
Formats a color as a CSS hex string (`#rrggbb` or `#rrggbbaa`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | Any | required | Color value |
include_alpha | Bool | optional | Include alpha channel as #RRGGBBAA |
Any(color/to-hex (color/RGB 1.0 0.0 0.0)) ; -> "#ff0000"to-hsl#
Converts any color value into cylindrical `HSL` (`h`, `s`, `l`, `a`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | RGB | RGBA | Oklch | HSL | String | Int | required | Input color struct, CSS color string, or 0xRRGGBB integer |
Any(color/to-hsl "#10b981")to-int#
Packs an RGB(A) color into a 32-bit `0xRRGGBBAA` or `0xAARRGGBB` integer.
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | RGB | RGBA | Oklch | HSL | String | Int | required | Input color struct, CSS color string, or 0xRRGGBB integer |
Any(color/to-int "#ffffff")to-oklch#
Converts any color value into perceptual Oklch (`l`, `c`, `h`, `a`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | RGB | RGBA | Oklch | HSL | String | Int | required | Input color struct, CSS color string, or 0xRRGGBB integer |
Any(color/to-oklch (color/RGB 0.2 0.4 0.9))to-rgb#
Converts any color value to 3-channel `RGB`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | RGB | RGBA | Oklch | HSL | String | Int | required | Input color struct, CSS color string, or 0xRRGGBB integer |
Any(color/to-rgb "#ff0000")to-rgba#
Converts any color value to 4-channel `RGBA`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | RGB | RGBA | Oklch | HSL | String | Int | required | Input color struct, CSS color string, or 0xRRGGBB integer |
Any(color/to-rgba "#ff000080")to-u8#
Converts `RGBA` floating channels (`0.0..1.0`) into `[r g b a]` bytes (`0..255`).
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | RGB | RGBA | Oklch | HSL | String | Int | required | Input color struct, CSS color string, or 0xRRGGBB integer |
Any(color/to-u8 (color/RGBA 1.0 0.5 0.0 1.0))with-alpha#
Returns a copy of `color` with its alpha channel set to `alpha`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
color | Any | required | Base color |
alpha | Float | required | Alpha channel 0.0..1.0 |
Any(color/with-alpha "#000000" 0.4)