Skip to content
colors

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 read145 words

Function Signature

js

rgbToLab(r: number, g: number, b: number): { L: number, a: number, b: number }

Parameters

  • r (number): Red channel value (0–255).
  • g (number): Green channel value (0–255).
  • b (number): Blue channel value (0–255).

Return Value

An object containing the Lab color components: L (lightness, 0–100), a (green–red axis), and b (blue–yellow axis).

js

rgbToLab(255, 102, 0);
// { L: ~62, a: ~58, b: ~70 }

rgbToLab(0, 170, 255);
// { L: ~66, a: ~-7, b: ~-41 }

rgbToLab(255, 255, 255);
// { L: 100, a: 0, b: 0 }

rgbToLab(0, 0, 0);
// { L: 0, a: 0, b: 0 }

Conversion Details

  • Internally, the function first converts RGB to CIE XYZ using rgbToXyz.
  • Then, the XYZ values are transformed into Lab using xyzToLab.
  • The Lab model is device-independent and standardized for perceptual uniformity.

Examples

js

// Bright red
console.log(rgbToLab(255, 0, 0));
// { L: ~53, a: ~80, b: ~67 }

// Forest green
console.log(rgbToLab(34, 139, 34));
// { L: ~50, a: ~-47, b: ~45 }

Usage Notes

  • The Lab space is useful for measuring perceptual differences between colors (ΔE calculations).
  • L ranges from 0 (black) to 100 (white).
  • a axis ranges from green (negative) to red (positive).
  • b axis ranges from blue (negative) to yellow (positive).

Previous

xyzToLab

Next

labToRgb


Top tools

BoardlyLinksyChromoCodeHub

ReadyTools

CareersContactTools
Pricing7 days free
GuidesDocsBlogUpdatesLaraVault

Select Language

Set theme

© 2026 ReadyTools. All rights reserved.