Guide
Understanding HEX, RGB, HSL and HSV color codes
By Logappradeep · ServiceNow developer
The same color can be written many ways. A designer hands you #3b82f6, a charting library wants rgb(59, 130, 246), and your theme file uses hsl(217, 91%, 60%). They all describe one shade of blue. A color converter translates between these notations so you can use whichever one the tool in front of you expects.
How the color models relate
RGB describes a color as amounts of red, green and blue light, each from 0 to 255. It maps directly to how screens produce color. HEX is just RGB written in hexadecimal: #3b82f6 splits into 3b, 82 and f6, which are 59, 130 and 246 in decimal. Three-digit shorthand like #fff doubles each digit, so it equals #ffffff, and an eight-digit form such as #3b82f680 adds an alpha channel.
HSL (hue, saturation, lightness) rearranges the same information into terms people find intuitive. Hue is an angle on the color wheel from 0° to 360° (0° red, 120° green, 240° blue), saturation is how vivid the color is, and lightness runs from black at 0% to white at 100%. HSV (hue, saturation, value) shares the hue but treats 100% value as the full-strength color rather than white. That is why most color pickers use HSV: the square you drag across is saturation and value. Our example blue is hsv(217, 76%, 96%).
Worked example
Enter #3b82f6 and the converter shows rgb(59, 130, 246), hsl(217, 91%, 60%) and hsv(217, 76%, 96%), plus a brightness of about 122 out of 255. Brightness uses the weighted formula (R × 299 + G × 587 + B × 114) / 1000, which reflects that the eye is far more sensitive to green than to blue. You can also type a CSS color name such as tomato or an rgb() string; if the color matches one of the named CSS colors, its name is shown.
When you need it
- Translating brand colors from a style guide into the format your CSS or design tokens use.
- Creating hover and disabled states by adjusting only the HSL lightness of a base color.
- Feeding colors into libraries or native platforms that accept only RGB values.
Pitfalls
HSL lightness is not perceived lightness. Yellow at hsl(60, 100%, 50%) looks far brighter than blue at hsl(240, 100%, 50%), even though both have 50% lightness, so do not rely on equal HSL values to produce balanced palettes. Brightness scores like the one here are also different from the WCAG relative luminance used for contrast ratios; check text contrast with a dedicated contrast checker. Converting between models involves rounding, so a round trip such as HEX to HSL and back may differ by one unit in a channel. Finally, CSS accepts HEX, RGB and HSL directly, but there is no hsv() function in CSS, so convert HSV values before using them in a stylesheet.
All conversion happens instantly in your browser with no network requests.