HEX vs RGB vs HSL explained
Try it now: Color Converter, free and private in your browser.
Open Color ConverterAll three formats can describe the same color. They differ in how easy they are to read and to adjust. Here is the AuraticHub blue in each:
HEX #173FBF
RGB rgb(23, 63, 191)
HSL hsl(226, 79%, 42%)
HEX
HEX is the most common format on the web. The six digits are three pairs for red, green and blue, each from 00 to FF. It is compact and easy to copy from design tools, but hard to adjust by eye.
RGB
RGB uses three numbers from 0 to 255 for red, green and blue. It is the same data as HEX written in decimal. Use it when you need to calculate with channel values, or add transparency with rgba().
HSL
HSL stands for hue, saturation and lightness. Hue is an angle on the color wheel from 0 to 360, and the other two are percentages. HSL matches how people think about color.
- Want a darker shade? Lower the lightness.
- Want a softer color? Lower the saturation.
- Want a related color? Shift the hue.
Transparency
To make a color see-through, add an alpha value. rgba(23, 63, 191, 0.5) and hsl(226 79% 42% / 0.5) are both 50% transparent. HEX can do it too with eight digits, where the last pair is the alpha: #173FBF80.
Contrast and accessibility
Color choice affects readability. WCAG asks for a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text. A mid-tone background can pass with white text and fail with black, so test both. Never rely on color alone to show meaning, such as red for errors, because some people cannot tell the difference.
Build a palette with HSL
Keep the hue fixed and vary the lightness to get a set of matching shades:
:root {
--brand-light: hsl(226, 79%, 92%);
--brand: hsl(226, 79%, 42%);
--brand-dark: hsl(226, 79%, 18%);
}
This is also how you can make a dark theme: keep the hues and flip the lightness values.
Which should you use?
Use HEX for copying colors between tools. Use HSL when building a palette or theme with light and dark variants. Use RGB when you need transparency or channel math. They all work in CSS, so convert freely.
FAQ
- What is the alpha channel?
- It controls opacity, from 0 (invisible) to 1 (solid). It is the fourth value in rgba() and hsla(), and the last pair in an 8-digit HEX.
- Do HEX and RGB give the same color?
- Yes. They store the same three values in different number systems.
- What does a 3-digit HEX like #FFF mean?
- It is shorthand where each digit is doubled, so #FFF is #FFFFFF.
- Which format is best for dark mode?
- HSL, because you can keep the hue and adjust lightness to make dark and light versions.