# Colore JS > colore-js is a TypeScript color library and CLI: CSS Color 4 parsing, OKLCH-based manipulation, WCAG 2 and APCA contrast with minimal-change repair, CSS Color 4 gamut mapping, and accessible light/dark design systems exported as shadcn/ui, Tailwind v4, CSS variables or DTCG tokens. Package `colore-js` on npm. These docs cover v2.0.1: `npm install colore-js` or `yarn add colore-js`. Legacy 1.x docs live under https://colorejs.dev/docs/1.4.4/introduction. Not the Color.js library (`colorjs.io`). Entry points: - `colore-js`: the fluent `Color` class (`colore(input)` or `new Color(input)`), parsing, validation, `generateSystem`, `audit`, `auditCssVariables`, `fixCssVariables`, `ensureContrast`. - `colore-js/fn`: tree-shakable standalone functions (`lighten`, `mix`, `contrastRatio`, `palette`, `categoricalColors`, …). - `npx colore-js inspect|theme|adjust|set|extract|preview|check|audit|fix|init`: CLI for reading a project's theme, rebranding and adjusting it in place, checking, auditing and fixing contrast, and installing the Colore agent skill (`init`). Every command takes `--json`; edits are dry runs until `--write`. Conventions that differ from other color libraries: - `/fn` functions that return a color return a CSS string: hex when the color fits sRGB, otherwise `color(display-p3 …)` or `oklch(…)`. `toHex` clips explicitly. - `contrastRatio` returns a number (WCAG 2 ratio, 1–21) and `contrastAPCA` returns the Lc magnitude (0–108). - `isReadable`, `ensureContrast` and `generateStates` take the same target options: `algorithm: 'wcag2' | 'apca'`, `level: 'aa' | 'aaa'`, `intent: 'text' | 'largeText' | 'ui' | 'focus' | 'decorative'`, or an explicit `target`. `generateSystem`, `audit`, `auditCssVariables` and `fixCssVariables` take `algorithm` and `level`, and `categoricalColors` takes `algorithm`, `level` and `target`. `contrastRatio`, `contrastAPCA` and `bestTextColor` take no options: `bestTextColor` picks by APCA from an optional list of candidates. - Percent amounts are 0–100 (`lighten(c, 10)` is 10%). Ratios (`mix`, `interpolate`) are 0–1. - Untagged `{ r, g, b }` objects are 0–255. `{ space: 'srgb', r, g, b }` is 0–1, like CSS `color(srgb …)` and Figma. Object outputs use `alpha`. - Unknown options and out-of-range inputs throw a `ColorError` that names the fix instead of returning a guessed color. - `generateSystem(brand)` keeps the brand color as the primary when it passes contrast (`preserveSeed` defaults to true). ## Start here - [Introduction](https://colorejs.dev/docs/introduction.md): Colore (colore-js) is a zero-dependency TypeScript color library. Mix colors in OKLCH, fix contrast automatically, and build light and dark themes. - [Get started](https://colorejs.dev/docs/getting-started.md): Install Colore and use it to change a button color or check text contrast. Start with a copyable example, then pick the import that fits your code. - [Coding agents and CLI](https://colorejs.dev/docs/agents.md): Install the Colore skill for Claude Code, Cursor or Codex. Ask your agent to rebrand an app, add dark mode or fix contrast through the Colore CLI. - [FAQ](https://colorejs.dev/docs/faq.md): Find quick answers about using Colore with OKLCH, Tailwind and shadcn/ui. See which contrast checks, color inputs and coding agents it supports. ## Guides - [Check color contrast in JavaScript](https://colorejs.dev/docs/guides/check-color-contrast.md): Check whether text passes WCAG contrast in JavaScript. Measure the color pair, repair a failing foreground, and check the result before you ship. - [Pick black or white text for a background color](https://colorejs.dev/docs/guides/black-or-white-text.md): Pick black or white text for any background color in JavaScript with one line. Compare the brightness, WCAG 2 and APCA methods and see where they disagree. - [Generate a shadcn/ui theme from one color](https://colorejs.dev/docs/guides/shadcn-theme-from-one-color.md): Generate light and dark shadcn/ui colors from one brand hex. Replace the color tokens in globals.css and check contrast in the exported theme. - [Tailwind CSS v4 colors from your brand color](https://colorejs.dev/docs/guides/tailwind-v4-colors.md): Turn one brand color into a 50–950 Tailwind CSS v4 palette. Export an @theme block and choose button shades by measuring the text contrast. - [Dark mode colors that pass contrast](https://colorejs.dev/docs/guides/dark-mode-colors.md): Build light and dark CSS palettes from a brand color. Check the contrast of page text, muted labels and primary buttons on their own surfaces. - [Use OKLCH in JavaScript](https://colorejs.dev/docs/guides/oklch-in-javascript.md): Convert a hex color to OKLCH, change its lightness and mix it with another color in JavaScript. Keep wide colors in CSS or map them to sRGB for hex. - [Accessible chart colors for dashboards](https://colorejs.dev/docs/guides/chart-colors.md): Generate dashboard series colors in JavaScript that stay distinct for red-green color blindness, in light and dark mode, with a cue beyond color. - [Handle invalid colors](https://colorejs.dev/docs/advanced/error-handling-and-validation.md): Validate colors from a form, file or third-party API. Catch a ColorError when you need the reason or use Color.try when a fallback is enough. - [Performance and bundling](https://colorejs.dev/docs/advanced/performance-and-bundling.md): Choose a Colore import for the work you do and measure its effect on your bundle. Learn when chaining saves repeated parsing and string conversions. ## API Reference - [API reference](https://colorejs.dev/docs/api/overview.md): Find the Colore function for parsing, mixing or converting colors. Browse references for contrast repair, palette generation and theme exports. ## API: Color Class - [Color constructor and inputs](https://colorejs.dev/docs/api/color-class/constructor-and-inputs.md): Create a Color from a CSS string, a typed object or another Color. Use tagged channels for Figma floats and inspect errors before accepting user input. - [Color static methods](https://colorejs.dev/docs/api/color-class/static-factory-methods.md): Create colors from RGB, HSL or OKLCH channels without assembling a string. Use Color.try to check an input and continue when the value is invalid. - [Color string output](https://colorejs.dev/docs/api/color-class/string-output-methods.md): Export a Color as hex, RGB, OKLCH or another CSS string. Use css() to keep wide-gamut colors, or choose one format when a file or API requires it. - [Color object output](https://colorejs.dev/docs/api/color-class/object-output-methods.md): Read a color as named channels or an array for your picker, renderer or export. Keep full numeric precision by choosing the channel space you need. - [Color utilities](https://colorejs.dev/docs/api/color-class/utility-methods.md): Compare channel values, read opacity or check a color gamut. Use Color utilities to inspect a color and keep the original available for other work. ## API: Parsing - [parse](https://colorejs.dev/docs/api/parsing/parse.md): Parse a CSS color string in JavaScript and get numeric channels plus alpha. Colore returns the same linear sRGB shape for each supported format. - [parseToSpace](https://colorejs.dev/docs/api/parsing/parse-to-space.md): Read named color channels from a CSS string in JavaScript. Use the space tag to access the source coordinates for sRGB, HSL, OKLCH, Display P3 and more. - [detectFormat](https://colorejs.dev/docs/api/parsing/detect-format.md): Identify hex, RGB, OKLCH, Display P3 and other CSS color formats in JavaScript. Use the return value to choose how to inspect or display an input. - [fromCssMix](https://colorejs.dev/docs/api/parsing/from-css-mix.md): Resolve a CSS color-mix() expression in JavaScript. Use Color.fromCssMix for chaining or parseColorMix to get a tagged linear sRGB color value. ## API: Validation - [isValidColor](https://colorejs.dev/docs/api/validation/is-valid-color.md): Check whether Colore can parse a CSS color string in JavaScript. Get a boolean for form fields, design tokens or colors copied from a stylesheet. ## API: Output - [toHex](https://colorejs.dev/docs/api/operations/output/to-hex.md): Convert OKLCH, RGB, HSL or any CSS color to hex in JavaScript with one call. Handles alpha, and can gamut-map vivid OKLCH colors so the hex stays close. - [toRgb](https://colorejs.dev/docs/api/operations/output/to-rgb.md): Convert hex, HSL or another supported color to RGB in JavaScript. Get a modern CSS rgb() string with integer sRGB channels and optional alpha. - [toHsl](https://colorejs.dev/docs/api/operations/output/to-hsl.md): Convert hex, RGB or another supported color to HSL in JavaScript. Get a CSS hsl() string with degrees, percentages and optional slash-separated alpha. - [toOklab](https://colorejs.dev/docs/api/operations/output/to-oklab.md): Convert a CSS color to OKLab in JavaScript. Get an oklab() string for perceptual color work or read the lightness and opponent channels as numbers. - [toOklch](https://colorejs.dev/docs/api/operations/output/to-oklch.md): Convert hex to OKLCH in JavaScript. Get a CSS oklch() string or read lightness, chroma and hue as numbers, while keeping wide-gamut color values. - [toCss](https://colorejs.dev/docs/api/operations/output/to-css.md): Output a color as CSS in JavaScript. Colore selects hex, Display P3 or OKLCH based on gamut so colors beyond sRGB can keep their wider range. - [mixToCss](https://colorejs.dev/docs/api/operations/output/mix-to-css.md): Generate a CSS color-mix() expression in JavaScript from two colors. Pick the interpolation space and the second color’s weight for browser output. ## API: Manipulation - [lighten](https://colorejs.dev/docs/api/operations/manipulation/lighten.md): Lighten a CSS color in JavaScript or TypeScript. Move its OKLCH lightness toward white while keeping the hue for hover states and palette edits. - [darken](https://colorejs.dev/docs/api/operations/manipulation/darken.md): Darken a color in JavaScript or TypeScript. Colore lowers OKLCH lightness while keeping hue and chroma, so a pressed state keeps its brand color. - [saturate](https://colorejs.dev/docs/api/operations/manipulation/saturate.md): Make a color more vivid in JavaScript by increasing OKLCH chroma. Colore keeps the original lightness and hue and can output a wider-gamut color. - [desaturate](https://colorejs.dev/docs/api/operations/manipulation/desaturate.md): Soften a color in JavaScript by lowering its OKLCH chroma. Keep its lightness and hue for quieter accents, secondary tokens or a matching gray. - [adjustHue](https://colorejs.dev/docs/api/operations/manipulation/adjust-hue.md): Rotate a color’s hue in JavaScript using OKLCH. Keep its lightness and chroma, wrap angles around the wheel, and output wide-gamut CSS when needed. - [grayscale](https://colorejs.dev/docs/api/operations/manipulation/grayscale.md): Convert any supported CSS color to gray in JavaScript. Colore removes OKLCH chroma while preserving lightness and opacity for a matching neutral. - [invert](https://colorejs.dev/docs/api/operations/manipulation/invert.md): Invert a color in JavaScript by flipping its sRGB channels and keeping its opacity. Convert a CSS color to a negative for an icon or preview. - [setAlpha](https://colorejs.dev/docs/api/operations/manipulation/set-alpha.md): Set the opacity of a CSS color in JavaScript. Replace the alpha channel and keep the color itself, with eight-digit hex or wide-gamut CSS output. - [setOklch](https://colorejs.dev/docs/api/operations/manipulation/set-oklch.md): Set exact OKLCH lightness, chroma or hue in JavaScript. Keep any channel you leave out, or tint a gray by giving it a new hue and chroma together. - [mix](https://colorejs.dev/docs/api/operations/manipulation/mix.md): Mix two CSS colors in JavaScript using OKLab, OKLCH, sRGB or another supported space. Set the share of the second color to get the blend you need. ## API: Harmony - [complement](https://colorejs.dev/docs/api/operations/manipulation/complement.md): Find a color’s complement in JavaScript by rotating its OKLCH hue by 180 degrees. Colore reduces chroma when needed to keep the result in gamut. - [triadic](https://colorejs.dev/docs/api/operations/harmony/triadic.md): Generate a three-color scheme from one color in JavaScript. Colore spaces the hues 120 degrees apart and fits the partners into sRGB or Display P3. ## API: Accessibility - [contrastRatio](https://colorejs.dev/docs/api/operations/accessibility/contrast-ratio-wcag.md): Calculate the WCAG 2 contrast ratio between text and a background in JavaScript. Colore accounts for opacity before calculating the ratio. - [contrastAPCA](https://colorejs.dev/docs/api/operations/accessibility/contrast-apca.md): Measure the APCA lightness contrast of text on a background in JavaScript. Colore returns an Lc magnitude you can compare with your target. - [luminance](https://colorejs.dev/docs/api/operations/accessibility/luminance.md): Measure relative luminance for any supported sRGB color in JavaScript. Use the same channel weights as WCAG 2 to compare colors or build a checker. - [isReadable](https://colorejs.dev/docs/api/operations/accessibility/is-readable.md): Check if text passes WCAG AA or AAA contrast in JavaScript. Choose a target for normal text, large text or UI colors and get a pass or fail. - [bestTextColor](https://colorejs.dev/docs/api/operations/accessibility/best-text-color.md): Pick the text color with the highest APCA contrast on any background in JavaScript: black or white by default, or colors from your own palette. - [ensureContrast](https://colorejs.dev/docs/api/intelligence/ensure-contrast.md): Fix a failing foreground color in JavaScript. Colore searches for a small lightness change that reaches your WCAG 2 ratio or APCA target. - [simulate](https://colorejs.dev/docs/api/operations/scales-and-palette/simulate-color-blindness.md): Preview how a CSS color may look under different forms of color vision deficiency. Use the simulated colors to review chart series and UI states. - [audit](https://colorejs.dev/docs/api/audit.md): Audit a named color palette or CSS theme for contrast in JavaScript. Get measured failures, suggested fixes and warnings for palette colors. ## API: Distance - [deltaE](https://colorejs.dev/docs/api/operations/distance/delta-e.md): Measure perceptual color difference with CIEDE2000 in JavaScript. Compare two colors with standard weights or tune lightness, chroma and hue. - [deltaEOK](https://colorejs.dev/docs/api/operations/distance/delta-e-ok.md): Measure the perceptual distance between two colors in OKLab. Use the same metric Colore applies when finding the nearest color in a palette. - [nearest](https://colorejs.dev/docs/api/operations/distance/nearest.md): Find the closest color in a list of swatches or tokens in JavaScript. Colore compares colors in OKLab and gives you the match and its index. - [nearestNamed](https://colorejs.dev/docs/api/operations/distance/nearest-named.md): Find the nearest CSS named color to a hex, RGB or OKLCH value. Colore returns the name, color and OKLab distance for a readable swatch label. ## API: Scales & Interpolation - [scale](https://colorejs.dev/docs/api/operations/scales-and-palette/scale.md): Build a stepped color scale between two colors in JavaScript. Choose the number of stops and the color space to use for the colors between them. - [interpolate](https://colorejs.dev/docs/api/operations/scales-and-palette/interpolate.md): Sample a color between gradient stops in JavaScript. Choose the position and interpolation space, and keep wide-gamut results as CSS values. - [palette](https://colorejs.dev/docs/api/operations/scales-and-palette/palette.md): Generate a Tailwind-style 50–950 shade ramp from a brand color in JavaScript. Colore places your seed exactly at its closest lightness step. - [categoricalColors](https://colorejs.dev/docs/api/operations/scales-and-palette/categorical-colors.md): Generate distinct chart colors for light and dark backgrounds. Colore considers red-green vision and checks generated colors against a contrast target. ## API: Design System - [generateSystem](https://colorejs.dev/docs/api/system/generate-system.md): Generate a light and dark theme from one brand color in JavaScript. Colore creates semantic roles, shade ramps and contrast-checked text pairs. - [inspectCssTheme](https://colorejs.dev/docs/api/system/inspect-css-theme.md): Read a shadcn/ui, Tailwind CSS v4 or plain CSS theme file and get its brand color, light and dark modes, value format and missing tokens in one call. - [applyThemeToCss](https://colorejs.dev/docs/api/system/apply-theme-to-css.md): Rebrand a shadcn/ui, Tailwind CSS v4 or plain CSS theme from one brand color. Keeps your variable names and format, and adds a missing dark mode. - [adjustCssVariables](https://colorejs.dev/docs/api/system/adjust-css-variables.md): Make a CSS theme warmer, softer or darker by shifting OKLCH lightness, chroma or hue for chosen tokens and modes. Works with shadcn/ui and Tailwind. - [toTailwindCss, toShadcnCss and toDTCG](https://colorejs.dev/docs/api/system/system-to-tailwind-css.md): Export a generated color system to Tailwind CSS v4, shadcn/ui or DTCG design tokens. Use the same light and dark colors in your chosen format. - [generateStates](https://colorejs.dev/docs/api/system/states.md): Generate hover, active, disabled and focus colors for a button. Give Colore the background to check disabled and focus contrast after blending. ## API: Reference - [Entry points and exports](https://colorejs.dev/docs/api/reference/entry-points-and-exports.md): Find every public Colore export in the root and fn entry points. Choose a direct import for one operation or use the Color class to chain edits. - [TypeScript types](https://colorejs.dev/docs/api/reference/types.md): Type your color inputs, options and results with Colore’s public types. Find the right channel units and tagged object shape before passing values around. ## Concepts - [Color inputs and detection](https://colorejs.dev/docs/concepts/color-inputs-and-detection.md): Pass CSS strings, packed integers or tagged channel objects to Colore. Choose the right RGB units and see when the original input format is available. - [Color spaces and ranges](https://colorejs.dev/docs/concepts/color-spaces-and-ranges.md): Look up channel ranges for sRGB, Display P3, Lab and OKLCH. Pick the right units when you pass a color object or read numeric coordinates from Colore. - [Gamut and CSS output](https://colorejs.dev/docs/concepts/gamut-and-css-output.md): Output wide-gamut Display P3 and OKLCH colors in JavaScript. Keep the color in CSS or use a CSS Color 4 mapping method to create an sRGB fallback. - [Immutability and chaining](https://colorejs.dev/docs/concepts/immutability-and-chaining.md): Start from one color and derive hover, active or other variants while keeping the original. Chain your changes before converting the result to CSS. - [Precision, rounding and equality](https://colorejs.dev/docs/concepts/precision-rounding-and-equality.md): See where Colore rounds CSS output and where numeric values keep their precision. Compare channels for equality or choose a perceptual distance. ## Comparisons - [Colore compared](https://colorejs.dev/docs/comparison.md): Compare Chroma.js, Culori, Color.js, tinycolor2 and colord with Colore feature by feature: OKLCH and wide gamut, contrast, themes and bundle size. - [Colore and chroma.js compared](https://colorejs.dev/docs/comparison/chroma-js.md): Chroma.js changes OKLCH colors outside sRGB and can't read Display P3. Compare five common tasks in both libraries, plus contrast repair and themes. - [Moving from tinycolor2 to Colore](https://colorejs.dev/docs/comparison/tinycolor2.md): TinyColor (tinycolor2) turns oklch() and Display P3 colors into black. Map each tinycolor2 call to Colore and see which results change when you switch. ## Release - [Colore 2.0](https://colorejs.dev/docs/release/v2-release-notes.md): What is new in Colore 2.0: rebuilt on OKLCH, readable contrast by default, themes from one brand color, a coding-agent skill, and how to upgrade. ## Optional - [Full documentation in one file](https://colorejs.dev/llms-full.txt): every page above as Markdown - [Legacy 1.x documentation](https://colorejs.dev/docs/1.4.4/introduction): the previous major version - [Source repository](https://github.com/mallikcheripally/colore-js) - [npm package](https://www.npmjs.com/package/colore-js)