RGB to HEX
Converting RGB to HEX
Digital colors can be written three ways — HEX, RGB, and HSL — and converting RGB to HEX is always mathematically exact: they are three notations for the identical color, never approximations. #3b82f6, rgb(59,130,246), and hsl(217,91%,60%) are one color in three languages.
Which Format When
HEX dominates design mockups and CSS shorthand; RGB/RGBA is what you need when transparency (the alpha channel) enters the picture; HSL is the human-friendly one — tweak the lightness for shades and tints without touching the hue. Professionals pick palettes in HSL, then ship in HEX or RGB.
Practical Tips
Alpha cannot be expressed in 6-digit HEX — use 8-digit HEX or RGBA. And remember: converting between these formats never changes the color, but converting between color spaces (sRGB vs CMYK for print) absolutely can — that is a different conversion entirely.