Skip to content

Colorizr Class

The Colorizr class wraps all library functionality around a single color instance.

import Colorizr from 'colorizr';
const color = new Colorizr(color: string | ColorModel, options?: ColorizrOptions);
ParameterDescriptionType
colorAny CSS color string or a color model object (HSL, RGB, LAB, LCH).string | ColorModel
options.formatOutput format. Defaults to the input format.ColorType
const a = new Colorizr('#ff0044');
const b = new Colorizr('rgb(255 0 68)');
const c = new Colorizr({ h: 344, s: 100, l: 50 });
const d = new Colorizr('#ff0044', { format: 'oklch' });
PropertyTypeDescription
hexHEXHex representation
hslHSLHSL object
rgbRGBRGB object
oklabLABOkLab object
oklchLCHOkLCH object
alphanumberAlpha value (0-1)
typeColorTypeCurrent output format
const color = new Colorizr('#ff0044');
color.hex; // '#ff0044'
color.hsl; // { h: 344, s: 100, l: 50 }
color.rgb; // { r: 255, g: 0, b: 68 }
color.oklab; // { l: 0.63269, a: 0.23887, b: 0.08648 }
color.oklch; // { l: 0.63269, c: 0.25404, h: 19.90224 }
color.alpha; // 1
color.type; // 'hex'
GetterTypeDescription
cssstringCSS string in the current format
rednumberRed channel (0-255)
greennumberGreen channel (0-255)
bluenumberBlue channel (0-255)
huenumberHue (0-360)
saturationnumberSaturation (0-100)
lightnessnumberLightness (0-100)
luminancenumberWCAG relative luminance (0-1)
chromanumberChroma value (0-1)
opacitynumberOpacity value (0-1)
readableColorstringMost readable text color for this background
color.brightnessDifference(input: string): number
color.colorDifference(input: string): number
color.compare(input: string): Analysis
color.contrast(input: string): number
color.deltaE(input: string): number
color.lighten(amount: number): string
color.darken(amount: number): string
color.saturate(amount: number): string
color.desaturate(amount: number): string
color.grayscale(): string
color.invert(): string
color.rotate(degrees: number): string
color.opacify(alpha?: number): string // default: 0.9
color.transparentize(alpha?: number): string // default: 0.1
color.mix(color: string, ratio?: number, options?: MixOptions): string
color.format(type: ColorType, precision?: number): string
color.toGamut(format?: ColorType): string
const color = new Colorizr('#ff0044');
color.luminance; // 0.2168
color.contrast('#fff'); // 3.94
color.compare('#fff'); // { contrast: 3.94, normalAA: false, ... }
color.lighten(20); // '#ff668f'
color.mix('#0066ff'); // '#bc34d7'
color.format('oklch'); // 'oklch(63.269% 0.25404 19.902)'