ChromaKit logo

ChromaKit

DemoDocsGitHub

Color Utilities

Every conversion and helper the picker uses internally is exported, so you can parse, convert, and analyze colors without rendering any UI.

Live converter

parseColor accepts any format; rgbaToColorValue expands it into all of them. The demo below parses your input and shows formatColor output for each space.

hex#6366f1
rgbrgb(99, 102, 241)
rgbargba(99, 102, 241, 1.00)
hslhsl(239, 84%, 67%)
hslahsla(239, 84%, 67%, 1.00)
oklchoklch(59% 0.20 277)
oklchaoklch(59% 0.20 277 / 1.00)

Parse & format

Turn strings into structured colors and back again.

FunctionSignatureDescription
parseColor(color: string) => RGBA | nullParse any supported format string to RGBA.
parseHex(hex: string) => RGBA | nullParse a 3/6/8-digit hex string.
rgbaToColorValue(rgba: RGBA) => ColorValueExpand an RGBA into every format at once.
formatColor(color: ColorValue, format: ColorFormat) => stringRender a ColorValue as a CSS string.

Hex

RGBA ↔ hex.

FunctionSignatureDescription
rgbaToHex(rgba: RGBA) => string6-digit hex.
rgbaToHex8(rgba: RGBA) => string8-digit hex (with alpha).

HSL & HSV

Cylindrical RGB models.

FunctionSignatureDescription
rgbToHsl(rgb: RGB) => HSLRGB → HSL.
hslToRgb(hsl: HSL) => RGBHSL → RGB.
rgbaToHsla(rgba: RGBA) => HSLARGBA → HSLA.
hslaToRgba(hsla: HSLA) => RGBAHSLA → RGBA.
rgbToHsv(rgb: RGB) => HSVRGB → HSV.
hsvToRgb(hsv: HSV) => RGBHSV → RGB.
rgbaToHsva(rgba: RGBA) => HSVARGBA → HSVA.
hsvaToRgba(hsva: HSVA) => RGBAHSVA → RGBA.

OKLAB & OKLCH

Perceptually uniform spaces.

FunctionSignatureDescription
rgbToOklab(rgb: RGB) => OKLABRGB → OKLAB.
oklabToRgb(oklab: OKLAB) => RGBOKLAB → RGB.
rgbToOklch(rgb: RGB) => OKLCHRGB → OKLCH.
oklchToRgb(oklch: OKLCH) => RGBOKLCH → RGB.
oklabToOklch(oklab: OKLAB) => OKLCHOKLAB → OKLCH.
oklchToOklab(oklch: OKLCH) => OKLABOKLCH → OKLAB.
rgbaToOklaba(rgba: RGBA) => OKLABARGBA → OKLABA.
oklabaToRgba(oklaba: OKLABA) => RGBAOKLABA → RGBA.
rgbaToOklcha(rgba: RGBA) => OKLCHARGBA → OKLCHA.
oklchaToRgba(oklcha: OKLCHA) => RGBAOKLCHA → RGBA.

Color helpers

Accessibility checks and harmony generators built on the conversions above.

FunctionSignatureDescription
getRelativeLuminance(rgb: RGB) => numberWCAG relative luminance.
getContrastRatio(a: RGB, b: RGB) => numberWCAG contrast ratio between two colors.
meetsContrastRatio(ratio, level: 'AA'|'AAA', size?) => booleanWhether a ratio passes a WCAG level.
getComplementaryColor(rgb: RGB) => RGBThe opposite hue.
getAnalogousColors(rgb: RGB, angle?) => RGB[]Neighboring hues.
getTriadicColors(rgb: RGB) => RGB[]Three evenly spaced hues.
getSplitComplementaryColors(rgb: RGB, angle?) => RGB[]Split-complementary scheme.
getTetradicColors(rgb: RGB, angle?) => RGB[]Four-color scheme.
getColorHistory() => string[]Read persisted color history.
addToColorHistory(color: string, maxSize?) => string[]Add a color to history.
clearColorHistory() => voidEmpty the stored history.
copyToClipboard(text: string) => Promise<boolean>Copy text, resolving to success.
import { parseColor, getContrastRatio, meetsContrastRatio } from 'chromakit-react';

const fg = parseColor('#1a1a1a');
const bg = parseColor('#ffffff');
const ratio = getContrastRatio(fg, bg);          // 18.1
const passes = meetsContrastRatio(ratio, 'AA');  // true