v1.0.0
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 Space | Description | Best Used For |
|---|---|---|
| RGB | Red, Green, Blue | Displays, digital imaging |
| HSL | Hue, Saturation, Lightness | Color selection, UI design |
| HWB | Hue, Whiteness, Blackness | Intuitive color picking |
| CMYK | Cyan, Magenta, Yellow, Black | Printing, publishing |
| OKLCH | Lightness, Chroma, Hue | Perceptually uniform manipulation |
| LAB | L*, a*, b* | Color science, color matching |
| LCH | L*, C*, h | Color difference calculations |
| Display P3 | Red, Green, Blue | Wide gamut displays |
| NCOL | Natural Color | Color 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
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
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 = 0RGB String Representations
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()) # #FF0000HSL (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
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
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
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.
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
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)
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
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
from colorium import from_oklch
color = from_oklch(0.5, 0.2, 180)Converting to OKLCH
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)
from colorium import from_lab
color = from_lab(50, 20, -30)Converting to LAB
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°)
from colorium import from_lch
color = from_lch(50, 30, 180)Converting to LCH
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+
from colorium import from_p3
# Colors in P3 space
color = from_p3(0.8, 0.3, 0.5)Converting to P3
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
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
| Method | Returns |
|---|---|
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
| Method | Format |
|---|---|
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
- Color Creation — All ways to create colors
- Color Manipulation — Color operations
- Color Conversion — Advanced conversion
Previous: Core Concepts Next: Color Creation →