Color Spaces

Colorium supports 10+ color spaces, each with unique characteristics and use cases. This guide covers all of them in detail.

Overview of Color Spaces

Color SpaceDescriptionBest Used For
RGBRed, Green, BlueDisplays, digital imaging
HSLHue, Saturation, LightnessColor selection, UI design
HWBHue, Whiteness, BlacknessIntuitive color picking
CMYKCyan, Magenta, Yellow, BlackPrinting, publishing
OKLCHLightness, Chroma, HuePerceptually uniform manipulation
LABL*, a*, b*Color science, color matching
LCHL*, C*, hColor difference calculations
Display P3Red, Green, BlueWide gamut displays
NCOLNatural ColorColor naming systems

RGB (Red, Green, Blue)

RGB is the most common color space, used in displays, cameras, and digital imaging.

Values and Ranges

  • Each channel: 0 to 255
  • 0 = minimum intensity
  • 255 = maximum intensity
1
2
3
4
5
6
7
8
9
10
11
12
13
from colorium import Color

# Pure colors
red = Color(255, 0, 0)
green = Color(0, 255, 0)
blue = Color(0, 0, 255)

# Custom colors
orange = Color(255, 165, 0)
purple = Color(128, 0, 128)

# Grayscale
gray = Color(128, 128, 128)

RGB Properties

1
2
3
4
5
6
7
8
9
10
11
12
13
from colorium import Color

color = Color(100, 150, 200)

# Access components
print(color.red)    # 100
print(color.green)  # 150
print(color.blue)   # 200

# Modify components
color.red = 255
color.green = 0
color.blue = 0

RGB String Representations

1
2
3
4
5
6
7
from colorium import Color

color = Color(255, 0, 0)

print(color.to_rgb_string())   # rgb(255, 0, 0)
print(color.to_rgba_string())  # rgba(255, 0, 0, 1.00)
print(color.to_hex_string())   # #FF0000

HSL (Hue, Saturation, Lightness)

HSL is a cylindrical color space that's more intuitive for color selection.

Components

  • Hue: Color angle (0-360°)
    • 0° = Red
    • 120° = Green
    • 240° = Blue
  • Saturation: Color intensity (0-1)
    • 0 = Grayscale
    • 1 = Full color
  • Lightness: Perceived brightness (0-1)
    • 0 = Black
    • 0.5 = Pure color
    • 1 = White
1
2
3
4
5
6
7
8
9
10
11
12
13
from colorium import from_hsl

# Pure red
red = from_hsl(0, 1.0, 0.5)

# Pastel color
pastel = from_hsl(200, 0.3, 0.7)

# Dark color
dark = from_hsl(120, 0.8, 0.2)

# Grayscale (saturation = 0)
gray = from_hsl(0, 0, 0.5)

Converting to HSL

1
2
3
4
5
6
7
8
from colorium import Color

color = Color(100, 150, 200)
hsl = color.to_hsl()

print(hsl['h'])  # Hue (0-360)
print(hsl['s'])  # Saturation (0-1)
print(hsl['l'])  # Lightness (0-1)

HSL String Representation

1
2
3
4
from colorium import Color

color = Color(255, 0, 0)
print(color.to_hsl_string())  # hsl(0, 100%, 50%)

HWB (Hue, Whiteness, Blackness)

HWB is a color space that's even more intuitive than HSL for color selection.

Components

  • Hue: Color angle (0-360°)
  • Whiteness: Amount of white (0-1)
  • Blackness: Amount of black (0-1)

The sum of whiteness and blackness cannot exceed 1.

1
2
3
4
5
6
7
8
9
10
11
12
13
from colorium import from_hwb

# Pure red
red = from_hwb(0, 0, 0)

# Pastel pink (white added)
pink = from_hwb(0, 0.5, 0)

# Dark red (black added)
dark_red = from_hwb(0, 0, 0.5)

# Gray (equal white and black)
gray = from_hwb(0, 0.5, 0.5)

Converting to HWB

1
2
3
4
5
6
7
8
from colorium import Color

color = Color(100, 150, 200)
hwb = color.to_hwb()

print(hwb['h'])  # Hue (0-360)
print(hwb['w'])  # Whiteness (0-1)
print(hwb['b'])  # Blackness (0-1)

CMYK (Cyan, Magenta, Yellow, Black)

CMYK is the subtractive color model used in printing.

Components

  • Cyan: Amount of cyan ink (0-1)
  • Magenta: Amount of magenta ink (0-1)
  • Yellow: Amount of yellow ink (0-1)
  • Black: Amount of black ink (0-1)
1
2
3
4
5
6
7
8
9
10
11
12
13
from colorium import from_cmyk

# Pure red
red = from_cmyk(0, 1.0, 1.0, 0)

# Pure black
black = from_cmyk(0, 0, 0, 1.0)

# Dark gray
gray = from_cmyk(0, 0, 0, 0.5)

# Rich black
rich_black = from_cmyk(0.5, 0.5, 0.5, 1.0)

Converting to CMYK

1
2
3
4
5
6
7
8
9
from colorium import Color

color = Color(100, 150, 200)
cmyk = color.to_cmyk()

print(cmyk['c'])  # Cyan (0-1)
print(cmyk['m'])  # Magenta (0-1)
print(cmyk['y'])  # Yellow (0-1)
print(cmyk['k'])  # Black (0-1)

OKLCH (Lightness, Chroma, Hue)

OKLCH is a modern perceptually uniform color space.

Components

  • Lightness: Perceived brightness (0-1)
  • Chroma: Color intensity (0-0.4+)
  • Hue: Color angle (0-360°)

OKLCH is superior to HSL for color manipulation because:

  • It's perceptually uniform
  • Hues maintain their appearance across lightness levels
  • Better for gradients and interpolation
1
2
3
from colorium import from_oklch

color = from_oklch(0.5, 0.2, 180)

Converting to OKLCH

1
2
3
4
5
6
7
8
from colorium import Color

color = Color(100, 150, 200)
oklch = color.to_oklch()

print(oklch['l'])  # Lightness (0-1)
print(oklch['c'])  # Chroma (0-0.4+)
print(oklch['h'])  # Hue (0-360)

CIE Lab*

LAB is a color space designed to approximate human vision.

Components

  • L*: Lightness (0-100)
  • a*: Green-Red axis (-128 to 128)
  • b*: Blue-Yellow axis (-128 to 128)
1
2
3
from colorium import from_lab

color = from_lab(50, 20, -30)

Converting to LAB

1
2
3
4
5
6
7
8
from colorium import Color

color = Color(100, 150, 200)
lab = color.to_lab()

print(lab['l'])  # Lightness (0-100)
print(lab['a'])  # a* (-128 to 128)
print(lab['b'])  # b* (-128 to 128)

CIE LCH (L*, C*, h)

LCH is a cylindrical representation of LAB.

Components

  • L*: Lightness (0-100)
  • C*: Chroma (0-100+)
  • h: Hue (0-360°)
1
2
3
from colorium import from_lch

color = from_lch(50, 30, 180)

Converting to LCH

1
2
3
4
5
6
7
8
from colorium import Color

color = Color(100, 150, 200)
lch = color.to_lch()

print(lch['l'])  # Lightness (0-100)
print(lch['c'])  # Chroma (0-100+)
print(lch['h'])  # Hue (0-360)

Display P3

Display P3 is a wide gamut color space used in modern displays.

Components

  • Red: 0-1+ (can exceed 1 for colors outside sRGB)
  • Green: 0-1+
  • Blue: 0-1+
1
2
3
4
from colorium import from_p3

# Colors in P3 space
color = from_p3(0.8, 0.3, 0.5)

Converting to P3

1
2
3
4
5
6
7
8
from colorium import Color

color = Color(100, 150, 200)
p3 = color.to_p3()

print(p3['r'])  # Red (0-1)
print(p3['g'])  # Green (0-1)
print(p3['b'])  # Blue (0-1)

Color Space Conversion

Colorium handles conversions between all supported color spaces automatically.

Direct Conversion

1
2
3
4
5
6
7
8
9
10
from colorium import from_hsl

# Create in one space
color = from_hsl(200, 0.8, 0.5)

# Get in another space
rgb = color.to_rgb()
hwb = color.to_hwb()
cmyk = color.to_cmyk()
oklch = color.to_oklch()

Conversion Methods

MethodReturns
to_rgb()RGB dictionary
to_hsl()HSL dictionary
to_hwb()HWB dictionary
to_cmyk()CMYK dictionary
to_oklch()OKLCH dictionary
to_lab()LAB dictionary
to_lch()LCH dictionary
to_p3()P3 dictionary

String Representations

MethodFormat
to_rgb_string()rgb(255, 0, 0)
to_hex_string()#FF0000
to_hsl_string()hsl(0, 100%, 50%)
to_hwb_string()hwb(0, 0%, 0%)
to_cmyk_string()cmyk(0%, 100%, 100%, 0%)
to_oklch_string()oklch(62.8% 0.258 29.2)
to_lab_string()lab(53.2% 80.1 67.2)
to_lch_string()lch(53.2% 104.5 40.0)
to_p3_string()color(display-p3 0.823 0.033 0.017)

Choosing the Right Color Space

Use RGB When:

  • Working with displays and screens
  • Reading/writing image files
  • Working with web colors

Use HSL When:

  • Selecting colors intuitively
  • Creating color palettes
  • UI/UX design
  • Color theming

Use HWB When:

  • Simpler color selection than HSL
  • Understanding color mixing

Use CMYK When:

  • Working with print media
  • Preparing documents for printing

Use OKLCH When:

  • Perceptually uniform color manipulation
  • Color interpolation and gradients
  • Modern CSS applications

Use LAB/LCH When:

  • Color science applications
  • Color difference calculations
  • Color matching systems

Use Display P3 When:

  • Wide gamut color work
  • Modern display support
  • Professional color grading

Next Steps


Previous: Core Concepts Next: Color Creation →

On this page
40 sections