RGB color distance formula: check your color match accuracy

Contents
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).
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.
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