Skip to content

Color Matching

TailTrace uses perceptual color matching based on the CIEDE2000 algorithm to find the closest Tailwind token for any color value.

Simple hex comparison fails because:

  1. Colors that look similar can have very different hex values

    • #3b82f6 and #3b83f6 are nearly identical visually but different in hex
  2. Colors that look different can be close in hex

    • Linear interpolation in RGB doesn’t match human perception
  3. Designers often use “close enough” colors

    • A designer might pick #3b83f6 when they meant #3b82f6

TailTrace uses the CIEDE2000 color difference formula, which measures perceptual color difference.

  1. Convert to LAB color space - Designed to be perceptually uniform
  2. Apply CIEDE2000 formula - Accounts for hue, chroma, and lightness
  3. Return Delta-E value - A number representing perceptual difference
ΔEMeaningExample
0IdenticalSame color
1.0Not noticeableImperceptible difference
2.3Just noticeableJND threshold
5.0Clearly differentVisible difference
10+Very differentObviously different colors

TailTrace’s color matching in @tailtrace/core:

import { parseColor, rgbToLab, deltaE2000 } from '@tailtrace/core';
// Parse colors to RGB
const inputRgb = parseColor('#3b83f6');
const tokenRgb = parseColor('#3b82f6');
// Convert to LAB
const inputLab = rgbToLab(inputRgb);
const tokenLab = rgbToLab(tokenRgb);
// Calculate Delta-E 2000
const difference = deltaE2000(inputLab, tokenLab);
console.log(difference); // ~0.73
// Classify confidence
if (difference === 0) {
// Exact match
} else if (difference <= 2.3) {
// Fuzzy match - close enough but not exact
} else {
// No match - too different
}

TailTrace supports these color formats:

FormatExampleSupported
Hex#3b82f6
RGBrgb(59, 130, 246)
RGBArgba(59, 130, 246, 0.5)
HSLhsl(217, 91%, 60%)
Namedblue

All colors are converted to sRGB then CIELAB for comparison.

Adjust deltaEThreshold based on your needs:

Use CaseThreshold
Strict design systems1.0
Standard (default)2.3
Lenient/legacy codebases5.0
{
"deltaEThreshold": 2.3
}
FormulaProsCons
Delta-E 76SimplePoor near neutrals
Delta-E 94BetterStill issues with blue hues
CIEDE2000Most accurateSlightly slower

TailTrace defaults to CIEDE2000 but exposes all three in @tailtrace/core:

import { deltaE76, deltaE94, deltaE2000 } from '@tailtrace/core';