HEX, RGB, and HSL Explained: A Designer's Field Guide
Every color on a screen is a mix of red, green, and blue light — but designers, developers, and design tools describe that mix in different notations. HEX is compact and universal in CSS, RGB maps directly to how displays work, and HSL matches how humans actually think about color. Converting between them is mechanical; knowing when to use each is craft. This guide covers both.
RGB: The Native Language of Screens
An RGB color gives each channel an intensity from 0 to 255 — that's 256 levels per channel and 256³ = 16,777,216 possible colors, the standard 24-bit palette. rgb(255, 0, 0) is pure red; rgb(0, 0, 0) is black (all light off); rgb(255, 255, 255) is white (all channels full). Equal values on all three channels always produce a neutral gray. An optional fourth value, alpha, adds transparency: rgba(0, 0, 0, 0.5) is 50% transparent black, the workhorse of overlays and shadows.
HEX: The Same Numbers in Base 16
A HEX code is simply the three RGB channels written in hexadecimal and concatenated: #RRGGBB. Hexadecimal digits run 0–9 then A–F, where FF equals 255. Worked example: rgb(26, 132, 102) → 26 = 1A, 132 = 84, 102 = 66 → #1A8466. Going the other way, split #FF6B35 into FF (255), 6B (107), 35 (53) → rgb(255, 107, 53), a warm orange. Three-digit shorthand doubles each digit: #F80 means #FF8800. Because HEX and RGB encode identical information, conversion between them is always lossless.
HSL: How Humans Describe Color
HSL reorganizes the same color space into Hue (position on the color wheel, 0–360°: red at 0°, green at 120°, blue at 240°), Saturation (0% gray to 100% vivid), and Lightness (0% black to 100% white). Its power is editability: to get a hover state, keep hue and saturation and nudge lightness; to build a monochrome palette, hold hue and vary the other two; to find a complementary accent, add 180° to the hue. Tasks that require recalculating all three RGB channels become single-slider adjustments in HSL, which is why modern design systems define palettes in it.
Choosing Colors That Pass Accessibility
Beautiful palettes fail if people can't read the text. The WCAG guidelines require a contrast ratio of at least 4.5:1 between text and its background for normal text, and 3:1 for large text (18pt+, or 14pt bold). Contrast is computed from relative luminance, which tracks the L-ish dimension of your colors: light gray text on white (#999 on #FFF ≈ 2.8:1) fails; #595959 on white (≈ 7:1) passes comfortably. Roughly 8% of men have some form of color-vision deficiency, so never encode meaning in hue alone — pair red/green status colors with icons or labels.
Practical Palette Tips
- 60-30-10 rule: a dominant neutral (~60%), a secondary color (~30%), and a vivid accent (~10%) produces balanced interfaces almost automatically.
- Derive, don't pick: generate tints and shades of a brand color by adjusting HSL lightness in even steps (e.g., 95/85/70/55/40/25%) for a consistent scale.
- Test in context: the same HEX looks different on dark and light backgrounds due to simultaneous contrast — always preview in the real layout.
- Mind the medium: screen RGB colors can't be reproduced exactly in CMYK print; convert early and check proofs if a color is brand-critical.
Is converting between HEX, RGB, and HSL lossless?
HEX ↔ RGB is perfectly lossless — identical numbers in different bases. RGB ↔ HSL round-trips can shift by a hair due to rounding to whole degrees and percent, which is visually imperceptible in practice.
What do the two extra digits in an 8-digit HEX code mean?
Alpha (opacity). #1A8466CC is the color #1A8466 at CC/FF ≈ 80% opacity. Four-digit shorthand like #F80C expands the same way. All modern browsers support it.
Why does my color look different on another screen?
Displays differ in calibration, brightness, and color gamut, and some render in wider spaces like Display-P3. The code defines the color; the hardware renders its own approximation. For critical brand work, check on several devices.
How do I find a readable text color for any background?
Compute the background's relative luminance and target a contrast ratio ≥ 4.5:1 — practically, near-white text on dark backgrounds and near-black (#1A1A1A–#333) on light ones. Contrast checkers automate the verification.