Three Dialects of the Same Light

Every pixel on a digital display generates light through tiny subpixels: Red, Green, and Blue. In web styling, developers have multiple notations to command these subpixels. Whether you write #2563EB, rgb(37, 99, 235), or hsl(221, 83%, 53%), your browser converts the value into the identical emission of photons.

Yet, choosing the right color format is not merely a syntactic habit. The format you choose determines how easily your design system can be maintained, how intuitively you can build programmatic hover states, and how cleanly you can manage theming in modern CSS architectures.

1. Hexadecimal Color Codes (HEX)

HEX notation is the veteran of the web. It is a base-16 representation of the three color channels packed into a single string prefixed with a hash symbol. Each channel receives two hexadecimal digits ranging from 00 (0 in decimal) to FF (255 in decimal).

/* Standard 6-digit syntax: #RRGGBB */
.button {
  background-color: #2563eb; /* Red: 0x25 (37), Green: 0x63 (99), Blue: 0xEB (235) */
}

/* 3-digit shorthand syntax: expands #RGB to #RRGGBB */
.card {
  background-color: #fff; /* Expands to #ffffff */
}

/* 8-digit syntax with alpha: #RRGGBBAA */
.overlay {
  background-color: #00000080; /* Black with 50% opacity (0x80 = 128 / 255) */
}

Strengths of HEX:

  • Compact Footprint: 6 to 7 characters makes it the shortest string format, ideal for JSON design tokens, Figma handoffs, and bundle size efficiency.
  • Universal Ecosystem Compatibility: Every graphic design software, 3D engine, and mobile SDK parses HEX without hesitation.

Weaknesses of HEX:

  • Zero Human Readability: Looking at #8B5CF6, virtually no designer can mentally determine its hue, saturation, or lightness without memorization.
  • Terrible for Math: Creating a hover state that is "10% darker" requires third-party preprocessors or manual color picker lookups.

2. Red, Green, Blue (RGB & RGBA)

RGB notation represents color as three integer values ranging from 0 to 255. Modern CSS Color Module Level 4 allows both legacy comma-separated syntax and modern space-separated syntax with a forward-slash for alpha transparency:

/* Legacy comma syntax */
.badge {
  background-color: rgba(37, 99, 235, 0.15);
}

/* Modern CSS Color 4 syntax */
.badge-modern {
  background-color: rgb(37 99 235 / 15%);
}

Strengths of RGB:

  • Direct Hardware Alignment: RGB values map 1:1 with canvas pixel buffers, WebGL shaders, and native display buffers.
  • Dynamic Manipulation: In JavaScript, iterating over raw RGB integers is computationally trivial compared to parsing hexadecimal strings.

Weaknesses of RGB:

  • Like HEX, RGB remains unintuitive for aesthetic adjustments. Increasing lightness requires increasing all three channels non-linearly while attempting not to distort the hue.

3. Hue, Saturation, Lightness (HSL & HSLA)

HSL was designed specifically to align with human psychological perception. Rather than asking "how much red voltage do I send to the diode?", HSL asks three intuitive questions:

  • Hue (0° to 360°): What color is it on the 360-degree color wheel? (0° = Red, 120° = Green, 240° = Blue).
  • Saturation (0% to 100%): How intense or pure is the color? (0% is completely grayscale, 100% is neon pure).
  • Lightness (0% to 100%): How much white or black is mixed in? (0% is solid black, 50% is the pure tonal base, 100% is pure white).
/* HSL Syntax: hsl(Hue Saturation% Lightness% / Alpha) */
:root {
  --brand-h: 221;
  --brand-s: 83%;
  --brand-l: 53%;
  
  --primary: hsl(var(--brand-h) var(--brand-s) var(--brand-l));
  /* Effortless hover state: simply drop lightness by 8% */
  --primary-hover: hsl(var(--brand-h) var(--brand-s) calc(var(--brand-l) - 8%));
  /* Subdued background: drop saturation and raise lightness */
  --primary-subtle: hsl(var(--brand-h) 40% 96%);
}

Format Comparison Matrix

Format Example Syntax Alpha Transparency Intuitive Tweaking Primary Recommendation
HEX #2563eb Yes (8-digit) Very Low Static Design Tokens, Figma Sync
RGB rgb(37 99 235) Yes (/ alpha) Low Canvas manipulation, JS pixel math
HSL hsl(221 83% 53%) Yes (/ alpha) Very High Design Systems, CSS Variables, Theming

Which One Should You Choose Today?

For most modern web development, the optimal strategy combines HEX for your foundational raw tokens (e.g. Tailwind configuration or brand guide JSON) and HSL (or emerging OKLCH) for runtime CSS Custom Properties. HSL makes generating dynamic hover states, active states, and dark mode transitions effortless without bloating your stylesheet with hundreds of manually hard-coded colors.