Documentation

colors

Utilidades modernas para conversi?n de colores, verificaci?n de contraste, interpolaci?n perceptual y generaci?n de paletas.

48 pages

48 results

Getting Started

Official guide to installing and using @readytools/colors.

2 min read

parseColor

The `parseColor` function parses common web color strings into structured JavaScript objects. It supports HEX, HEX alpha, RGB(A), HSL(A), OKLab, and OKLCH formats, including modern CSS space/slash alpha syntax.

1 min read

normalizeHex

The `normalizeHex` function standardizes a HEX color string into a full 6-digit lowercase format. It ensures consistent formatting and validation before further processing.

1 min read

isValidHex

The `isValidHex` function checks whether a given string is a valid 3-digit or 6-digit HEX color. It is a simple validation utility that ensures the input follows the HEX color format specification.

1 min read

hexToRgb

The `hexToRgb` function converts a HEX color string into an RGB object. It supports both 3-digit and 6-digit HEX formats and outputs the red, green, and blue components as integers between 0 and 255.

1 min read

rgbToHex

The `rgbToHex` function converts RGB component values into a lowercase HEX color string. Each channel is rounded, clamped to the 0-255 range, and converted into a two-digit hexadecimal value.

1 min read

hexAToRgba

The `hexAToRgba` function converts 4-digit or 8-digit HEX alpha colors into RGBA channel values.

1 min read

rgbaToHexA

The `rgbaToHexA` function converts RGBA values into an 8-digit HEX color string (`#rrggbbaa`). It encodes the alpha channel as the last two hexadecimal digits.

1 min read

hexToCmyk

The `hexToCmyk` function converts a HEX color string into CMYK components. It is especially useful for print workflows, where CMYK is the standard color model.

1 min read

rgbToHsl

The `rgbToHsl` function converts RGB color values into the HSL (Hue, Saturation, Lightness) color model. It outputs hue in degrees (0–360) and saturation/lightness as percentages (0–100).

1 min read

hslToRgb

The `hslToRgb` function converts HSL color values into the RGB color model. It outputs red, green, and blue components as integers from 0 to 255.

1 min read

rgbToXyz

The `rgbToXyz` function converts RGB values into the CIE XYZ color space using the D65 reference white. This is an intermediate step for converting to perceptual color spaces like Lab.

1 min read

xyzToLab

The `xyzToLab` function converts CIE XYZ tristimulus values into the CIE Lab color space. Lab is designed to be perceptually uniform, making it ideal for comparing colors based on human vision.

1 min read

rgbToLab

The `rgbToLab` function converts RGB color values into the CIE Lab color space. This color model is designed to approximate human vision, making it useful for perceptual color comparisons.

1 min read

labToRgb

The `labToRgb` function converts CIE Lab color values back into the RGB color model. It performs Lab → XYZ → RGB transformations and outputs red, green, and blue values as integers between 0 and 255.

1 min read

rgbToOklab

The `rgbToOklab` function converts RGB channel values to OKLab, a perceptual color space designed for smoother color operations.

1 min read

oklabToRgb

The `oklabToRgb` function converts OKLab values back to RGB channel values.

1 min read

hexToOklab

The `hexToOklab` function converts a HEX color directly to OKLab.

1 min read

oklabToHex

The `oklabToHex` function converts OKLab values to a HEX color string.

1 min read

rgbToOklch

The `rgbToOklch` function converts RGB channel values to OKLCH, the cylindrical form of OKLab.

1 min read

oklchToRgb

The `oklchToRgb` function converts OKLCH values back to RGB channel values.

1 min read

hexToOklch

The `hexToOklch` function converts a HEX color directly to OKLCH.

1 min read

oklchToHex

The `oklchToHex` function converts OKLCH values to a HEX color string.

1 min read

lighten

The `lighten` function increases the lightness of a HEX color by a specified percentage. It internally converts HEX → RGB → HSL, adjusts the lightness, and converts back to HEX.

1 min read

darken

The `darken` function decreases the lightness of a HEX color by a specified percentage. It is a wrapper around `lighten`, passing a negative adjustment to reduce brightness.

1 min read

saturate

The `saturate` function increases the saturation of a HEX color by a specified percentage. Internally, it converts HEX → RGB → HSL, adjusts the saturation, and converts back to HEX.

1 min read

desaturate

The `desaturate` function decreases the saturation of a HEX color by a specified percentage. It is a wrapper around `saturate`, applying a negative adjustment to reduce color intensity.

1 min read

adjustHue

The `adjustHue` function rotates the hue of a HEX color by a specified number of degrees. It preserves saturation and lightness while shifting the color’s position on the color wheel.

1 min read

invert

The `invert` function returns the inverse (complement) of a HEX color by subtracting each RGB component from 255. This produces the color opposite on the RGB spectrum.

1 min read

mix

The `mix` function blends two HEX colors together based on a weight factor. It interpolates the RGB values of both colors and outputs the result as a HEX string.

1 min read

interpolate

The `interpolate` function blends two HEX colors at a specific position and supports RGB, HSL, Lab, OKLab, and OKLCH interpolation.

1 min read

randomColor

The `randomColor` function generates random colors with optional constraints for hue, saturation, lightness, alpha, and output format.

1 min read

luminance

The `luminance` function calculates the relative luminance of a HEX color according to the WCAG definition. This value represents the perceived brightness of the color, normalized between 0 (black) and 1 (white).

1 min read

contrastRatio

The `contrastRatio` function calculates the WCAG contrast ratio between two colors, expressed as a number rounded to two decimals. The related `isAccessible` helper evaluates whether the contrast passes WCAG AA or AAA standards.

1 min read

ensureContrast

The `ensureContrast` function adjusts the lightness of a foreground color to ensure it meets a target WCAG contrast ratio against a background color. If the ratio is already sufficient, the original color is returned.

1 min read

getContrastColor

The `getContrastColor` function automatically chooses black (`#000000`) or white (`#ffffff`) based on which provides the best contrast against a given background color. It is useful for ensuring text remains legible regardless of background.

1 min read

deltaE76

The `deltaE76` function computes the perceptual difference between two colors using the CIE76 ΔE formula. It compares the colors in the Lab color space and returns a numeric value where lower values indicate greater similarity.

1 min read

deltaE2000

The `deltaE2000` function calculates CIEDE2000 color difference between two HEX colors. It is more perceptually accurate than simple Euclidean Lab distance.

1 min read

generateShades

The `generateShades` function produces a sequence of darker variants of a given HEX color. It progressively reduces the lightness in the HSL color model to generate shades, optionally including the base color.

1 min read

generateTints

The `generateTints` function produces a sequence of lighter variants of a given HEX color. It progressively increases the lightness in the HSL color model to generate tints, optionally including the base color.

1 min read

generateTones

The `generateTones` function produces a sequence of lower-saturation variants (tones) of a given HEX color. It progressively reduces the saturation in the HSL color model while keeping hue and lightness constant, optionally including the base color.

1 min read

generateHueVariants

The `generateHueVariants` function generates evenly spaced hue variants of a given HEX color across the entire color wheel. It uses hue rotation to create distinct variants, optionally including the base color as the first element.

1 min read

generateShadeScale

The `generateShadeScale` function creates a perceptually-even lightness scale derived from a base color using the CIE Lab color space. It can generate darker, lighter, or bidirectional scales with optional easing functions.

2 min read

scale

The `scale` function generates a sequence of colors between two HEX values. It uses `interpolate` internally and can blend in RGB, HSL, Lab, OKLab, or OKLCH space.

1 min read

palettes

The `palettes` module provides functions to generate common color harmony palettes based on hue relationships. These include complementary, analogous, triadic, and tetradic schemes, each returning an array of HEX colors.

1 min read

generateTailwindPalette

The `generateTailwindPalette` function creates Tailwind-like `50..950` color stops from a single base HEX color using OKLCH-based lightness and chroma shaping.

1 min read

generateTailwindConfig

The `generateTailwindConfig` function creates a Tailwind config fragment that can be spread into a Tailwind config file.

1 min read

toCSS

The `toCSS` function converts a HEX color into a valid CSS declaration string for a given property. It supports `hex`, `rgb`, `hsl`, `oklab`, and `oklch` output formats.

1 min read

Herramientas destacadas

BoardlyLinksyChromoHub de Código

ReadyTools

CarrerasContactoHerramientas
Precios7 días gratis
GuíasDocsBlogUpdatesLaraVault

Seleccionar idioma

Establecer tema

© 2026 ReadyTools. Todos los derechos reservados.