Skip to content

colors

Parse a color in whatever notation you got it, convert it between rgb, hsl and oklch, pick the text color that stays readable on top of it, and snap it to the nearest entry of a named palette.
Maven Centralbuild status

Read any notation

RgbColor.readColor() takes #a54e3c, #abc, rgb(165, 78, 60), hsl(12, 47%, 44%) or oklch(55.7% 0.108 34.7) and hands back an RgbColor. Invalid input returns null instead of throwing.

Convert between spaces →

Readable text on any background

Two contrast algorithms decide whether black or white text belongs on a given background — a hex-value threshold and a WCAG relative-luminance one. The swatches in these docs are colored by the first.

Compare both algorithms →

Three named palettes

The 64 colors of ColorPalette, the 286 of Tailwind CSS v4 and the 130 of Open Color — all behind one ColorCode interface, so nearest-color lookups work across all of them.

Browse the palettes →

Perceptual nearest color

getNearest() measures distance in OKLAB, where a step of the same size looks like the same step to the eye. #3b82f6 maps to blue-500, not to whatever happens to be close in rgb.

See how it picks →

Shades as a first-class concept

Shade maps the Tailwind steps 50–950 and the Open Color steps 0–9 onto one scale. Ask for Shade.mids() and you get accent-strength colors from either palette.

Generate random colors →

Small

Java 11, Lombok at compile time, Jackson and swagger-annotations as optional extras. Nothing else on the classpath at runtime.

Install in one line →