Questions ยท Developer Tools ยท 2 min read
HEX, RGB, or HSL: Which Color Notation When?
They are three spellings of the same colours, so choose by task: HEX for design tokens and copy-paste compactness, RGB(A) when code computes channels or needs alpha, HSL when humans adjust hue, saturation, or lightness directly. Conversion between them is lossless.
HEX: the lingua franca of palettes
#3498db packs three bytes into six characters, survives every design tool, CSS version, and platform, and compares cleanly in diffs. Its opacity shorthand (#3498db80) covers translucent cases too. When the goal is communicating an exact colour, hex is the lowest-friction notation.
Its weakness is meaning: nothing about #e74c3c says "slightly darker red than #c0392b". Hex encodes machines-first, humans-second.
RGB: computation and alpha
rgb(52, 152, 219) exposes channels as numbers, which is what code wants: darkening by scaling values, blending by averaging, deriving greys by averaging channels. rgba() adds transparency with a 0-1 alpha, and modern CSS accepts slash syntax (rgb(52 152 219 / 0.5)).
Channel arithmetic still fights perception: naive darkening skews hues because eyes weight green most. For perceptually sane adjustments, HSL or a proper colour library beats raw RGB math.
HSL: colours as adjustable dials
hsl(206, 70%, 53%) names a hue (position on the colour wheel), saturation (vividness), and lightness. Design systems love it: one hue constant plus lightness steps generates accessible ramps; swapping hue re-themes the set. "Same colour but lighter" is one number in HSL and channel guesswork elsewhere.
Caveat: HSL lightness is mathematical, not perceptual; yellow at 50% looks far brighter than blue at 50%. Fine for consistent systems, imperfect for judging contrast; check ratios separately.
Worth knowing before you start
- Conversion is exact among these three; nothing is lost translating hex to hsl and back.
- For wide-gamut work, newer notations (oklch, display-p3) exist; sRGB-era hex/rgb/hsl remain the interoperable baseline.
- Accessibility depends on contrast ratios, not notation; convert freely but always verify contrast.
Frequently asked questions
- Is HSL better for performance?
- No measurable difference; browsers convert everything internally anyway. Choose notation for readability and workflow, never speed.
- How do I add transparency to a hex colour?
- Append two hex digits for alpha: #3498db with 50% opacity becomes #3498db80. Or convert to rgb() with an alpha value; both render identically.
Related questions
All questions โ- UTC Offsets vs Time Zones: What Is the Difference?Offsets are static numbers; time zones are living histories of rules. Mixing them up is the root of most date bugs.
- SHA-256 vs SHA-512: Which Hash Should I Use?Both are excellent and neither is "broken". Pick by ecosystem defaults: 256 for broad compatibility, 512 where longer digests suit the job.
- What Actually Makes a Password Strong?Unpredictability measured in bits of entropy. Length contributes far more than symbol swaps, and humans are bad at both unaided.
- Are Online Password Generators Safe to Use?Local generation with a cryptographic random source is safe by construction. The failure mode to avoid is generators that transmit passwords.
Related guides
All guides โ- Planning Meetings Across Time Zones Without the GuessworkMost scheduling pain comes from three avoidable mistakes: trusting abbreviations, converting with the wrong date, and ignoring that the meeting lands on someone elseโs tomorrow.
- Daylight Saving and Time Conversion: The Mistakes That Break SchedulesOffsets are answers to "at what date?", not properties of a zone. Every classic DST bug โ drift, gaps, duplicates, hemisphere flips โ follows from forgetting that.
- A Markdown Workflow for Project DocumentationDocumentation dies when writing it hurts. Markdown plus a tight preview loop keeps the cost near zero.
- Generating Passwords You Can Actually TrustTrust comes from three sources: cryptographic randomness, sufficient length, and a generator that never sees the network. All three are checkable.
Related reading
All articles โ- Reading Regex Without FearRegex looks like line noise because it compresses a whole language into punctuation. Learn the eight moves and any pattern becomes parseable.
- Entropy, Explained for Normal PeopleForget "complexity rules". One number predicts whether a password survives attack, and it rewards length far more than exclamation marks.
- Why UUID v4 Collisions Almost Never HappenPeople hear "random" and expect collisions eventually. The numbers say otherwise: the universe ends first.
- Client-Side Tools Change the Privacy MathEvery uploaded file is a promise about storage and deletion. Files processed locally require no promises at all.