1. HEX: Web Hexadecimal Coordinate Encoding
Compact base-16 byte representation for web standards
Hexadecimal (HEX) color notation is the foundational standard of the World Wide Web. A standard 6-digit hex code like #4169E1 is a base-16 string representing three separate 8-bit bytes corresponding to Red, Green, and Blue channels.
Each channel can take values from 00 (decimal 0, zero intensity) to FF (decimal 255, maximum intensity). In #4169E1: 41 represents red (decimal 65), 69 represents green (decimal 105), and E1 represents blue (decimal 225). This compact format yields exactly 256 × 256 × 256 = 16,777,216 distinct possible colors — the standard sRGB 24-bit TrueColor spectrum.
Modern CSS also supports 8-digit hex notation (#RRGGBBAA), where the final two characters represent an 8-bit alpha transparency channel. For example, #4169E180 applies 50% opacity (128 / 255).
// How hex parsing works under the hood
function hexToRgb(hex: string) {
const clean = hex.replace('#', '');
const r = parseInt(clean.substring(0, 2), 16); // 0x41 -> 65
const g = parseInt(clean.substring(2, 4), 16); // 0x69 -> 105
const b = parseInt(clean.substring(4, 6), 16); // 0xE1 -> 225
return { r, g, b };
}
2. RGB & RGBA: Hardware-Direct Additive Light
The direct language of GPU framebuffers and subpixel emitters
RGB (Red, Green, Blue) is the native mathematical model of digital display hardware. When your operating system draws a button, the graphics card writes RGB integer triplets directly into video memory, which in turn drives the microscopic subpixel LEDs of your display.
In CSS, RGB is specified via rgb(red, green, blue) or rgba(red, green, blue, alpha). Modern CSS Color Module Level 4 simplified the syntax to space-separated values with an optional slash for alpha: rgb(37 99 235 / 0.85).
RGB is the premier format for programmatic color math: calculating linear luminance, matrix convolutions in WebGL shaders, image processing canvases, and direct canvas drawing.
3. HSL: Human-Centric Cylindrical Coordinates
The designer-friendly format for CSS custom properties
While computers love RGB, humans do not think in channel intensities. If someone asks you to make a button "slightly darker" or "more vibrant", adjusting RGB requires recalculating all three channels simultaneously.
HSL solves this by wrapping RGB into a cylindrical coordinate system: Hue (0°–360° on the color circle), Saturation (0%–100%), and Lightness (0%–100%).
To darken a color in HSL, you simply decrement the Lightness percentage while holding Hue and Saturation constant. This makes HSL exceptionally powerful for creating cohesive UI palettes with CSS variables, where a single base hue can power an entire suite of hover states, borders, and shadows.
/* Dynamic button hover states powered by HSL lightness math */
.btn-primary {
--btn-h: 215deg;
--btn-s: 85%;
--btn-l: 50%;
background-color: hsl(var(--btn-h) var(--btn-s) var(--btn-l));
color: #ffffff;
}
.btn-primary:hover {
/* Effortlessly darken background by 8% without changing hue or saturation */
background-color: hsl(var(--btn-h) var(--btn-s) calc(var(--btn-l) - 8%));
}
4. CMYK: Subtractive Ink Separation for Print
Four-color process printing for physical packaging and editorial
CMYK (Cyan, Magenta, Yellow, Key/Black) is not a screen color space; it is a mechanical recipe for commercial printing presses. Each percentage represents the dot halftone density of physical ink laid onto paper.
Crucially, the CMYK color gamut is significantly smaller than the sRGB screen gamut. Vibrant, neon screen colors — such as electric lime green (#00FF48) or radiant cyan (#00FFFF) — physically cannot be reproduced using standard CMYK process inks. If you send an RGB design to a commercial printer without CMYK proofing, the printer will automatically clip the out-of-gamut colors, resulting in muddy, desaturated print pieces.
For professional brand guidelines, always provide both calibrated digital hex/RGB values and verified CMYK (or Pantone spot color) specifications.
5. When to Use Which Format (Production Matrix)
Clear engineering guidelines for every phase of digital and physical delivery
Follow this production decision matrix to ensure seamless color fidelity across your tech stack:
| Use Case / Pipeline | Recommended Format | Why It Is The Best Choice |
|---|---|---|
| Static Web Styles & HTML | HEX (#4169E1) | Most concise syntax, universally supported across all browsers and email clients. |
| Interactive Design Tokens & Themes | HSL or OKLCH | Enables programmatic lightness and chroma adjustments using CSS calc(). |
| WebGL, Shaders & Canvas API | RGB / Float (0.0 to 1.0) | Directly maps to graphics pipeline vector registers without conversion overhead. |
| Packaging, Merch & Print Stationery | CMYK & Pantone Spot | Guarantees physical ink formulations match expectations on coated/uncoated paper. |
| Next-Gen Wide Gamut (HDR / Display P3) | OKLCH or color(display-p3) | Enables 25% richer, more vibrant colors on modern Mac, iPhone, and OLED screens. |
Key Editorial Takeaways
- HEX is the most compact and universal format for static digital styles and design handoffs.
- RGB represents direct hardware subpixel values, ideal for canvas and computational graphics.
- HSL is the most intuitive format for creating programmatic color variations and hover states in CSS.
- CMYK has a smaller color gamut than digital screens; always proof printed materials in CMYK before press runs.
- For future-proof design systems, adopt OKLCH to access wide-gamut Display P3 colors with true perceptual uniformity.