RGB color distance formula: check your color match accuracy

PublishedToolColor Matching Game (Guess the Shade)

Contents
  1. The problem with matching color by eye
  2. How to calculate color error with the RGB distance formula
  3. What to keep in mind when applying color training to real work
  4. Summary
  5. Frequently asked questions

The problem with matching color by eye

When designers and developers tweak UI colors to match a target, it's common for two colors to look nearly identical on screen while their actual RGB values are far apart. That gets especially tricky with tone-on-tone palettes, where the differences in lightness and saturation are tiny, and your eyes alone can't judge the gap. A measurable standard for color difference makes those calls more objective.

How to calculate color error with the RGB distance formula

In computer graphics, the difference between two colors C₁(R₁, G₁, B₁) and C₂(R₂, G₂, B₂) is calculated as the Euclidean distance between them in 3D RGB space. If we call that distance d, the formula looks like this. (Note: ΔE, which means color difference, usually refers to formulas based on the CIE Lab color space such as CIE76/94/2000. The d below is a plain Euclidean distance in RGB space, so it's not the same value as ΔE.)

d = √((R₂ - R₁)² + (G₂ - G₁)² + (B₂ - B₁)²)

The largest possible distance in RGB space happens when each of R, G, and B differs by 255, which works out to √(255² + 255² + 255²) ≈ 441.67. Using that maximum as the baseline, you can convert a distance into a match rate (%) between 0 and 100.

Match rate (%) = max(0, 100 × (1 − d ÷ 441.67))

Here's what that looks like as a JavaScript function.

function calculateColorMatchScore(targetRgb, userRgb) {
  const dr = targetRgb.r - userRgb.r;
  const dg = targetRgb.g - userRgb.g;
  const db = targetRgb.b - userRgb.b;

  const distance = Math.sqrt(dr * dr + dg * dg + db * db);
  const maxDistance = 441.673;

  const accuracy = Math.max(0, 100 * (1 - distance / maxDistance));
  return Math.round(accuracy); // round to a whole number (e.g., 87%, no decimals)
}

Instead of working through the formula by hand every time, it's faster to look at the target color on screen, match it with sliders, and see your match rate update live. If you'd rather skip the math and just check, try it with our free Color Matching Game (Guess the Shade).

Color Matching Game (Guess the Shade)

Match a randomly generated target color with RGB sliders and test how well you can judge color differences.

What to keep in mind when applying color training to real work

Item

Description

Getting a feel for tone-on-tone

Rather than dragging all three sliders at once, set R to the target first, then narrow G and then B. You'll close the gap faster that way.

Checking contrast ratio

If you also check that the contrast ratio between background and text stays at or above the WCAG threshold of 4.5:1, you cover readability and design at the same time.

Target match rate

Practicing until you can repeatedly hit a match rate of 95% or higher with the sliders builds your sense for spotting color error.

Note Rather than memorizing RGB numbers in theory, matching the target color on screen with the sliders and seeing the actual error with your own eyes is more effective for training your sense.

Summary

Color error can be calculated as the Euclidean distance between RGB values, and normalizing it gives you a match rate between 0 and 100. Set a target of 95% or higher and practice repeatedly to build a feel for subtle tone differences. Narrowing the R, G, and B sliders one at a time is a useful way to develop a sense for tone-on-tone palettes, and checking the WCAG contrast threshold (4.5:1 or higher) along the way gives you color skills you can apply on the job right away.

Color Matching Game (Guess the Shade)

Match a randomly generated target color with RGB sliders and test how well you can judge color differences.

Frequently asked questions

What formula is used to calculate the color match error?

It treats each color as a point in RGB vector space and calculates the Euclidean distance between the target color and the color you entered. The closer the two colors are, the closer the match rate gets to 100%.

How do I see the rating feedback in the game?

After you match a color with the sliders and submit, the game analyzes and shows your precision error rate (%) against the target color, along with a rating for that error range and your past matching history.

How many recent attempts can I review?

Your last 10 submissions stack up at the bottom of the screen, so you can compare the target color, the color you matched, and the match rate (%) for each round side by side.

This article was adapted from our Korean original. Read the Korean original

Related articles

  1. Color Palette Generator: Why Random Colors Still HarmonizeSee how a palette generator picks 5 random colors that still harmonize, using hue angles plus fixed saturation and lightness ranges you can check by hand.
  2. What Is a Complementary Color? 180° Rule and HSL AnglesA complementary color sits exactly 180° away on the color wheel. See how analogous, triadic, and tetradic schemes split the hue circle, plus the HSL math.
  3. CSS Keyframes Animation Timeline Formula and 60fps GuideLearn how CSS keyframe animations interpolate values, writing fade and pulse effects, and keeping motion at 60fps with transform and opacity.
  4. CSS Blob Shapes: 8-Value border-radius Formula GuideLearn how to build organic blob shapes in CSS with the eight-value border-radius formula, plus a hover animation that morphs the shape smoothly.
  5. box-shadow syntax: value order, inset meaning, stacked shadowsLearn what box-shadow values do — offset-x, offset-y, blur, spread, color — how inset flips the shadow inward, and how comma-stacked shadows add depth.
  6. CSS Button Hover Effects: Shine, 3D Press, and Slide FillHow CSS button hover effects work: diagonal shine, 3D press, and slide fill, built with pseudo-elements, transform, and box-shadow. Copy the CSS.

Related tools