Color Converter
Convert a color between HEX, RGB and HSL with a live preview, then read how each value is calculated and where each format fits.
#3b82f6, #38f, 3b82f6, rgb(59, 130, 246) and hsl(217, 91%, 60%). The result updates while you type.
Conversion result
The swatch and the three values below always describe the same color.
| Format | Value | What the numbers mean |
|---|---|---|
| HEX | #3b82f6 |
Three byte pairs written in base 16 |
| RGB | rgb(59, 130, 246) |
Red, green and blue channels from 0 to 255 |
| HSL | hsl(217, 91%, 60%) |
Hue in degrees, saturation and lightness in percent |
Color format cheat sheet
| Format | Example | Channel range | Alpha support |
|---|---|---|---|
| HEX | #3b82f6 | 00 to ff per pair | 8 digits: #3b82f680 |
| RGB | rgb(59, 130, 246) | 0 to 255 per channel | rgba(59, 130, 246, 0.5) |
| HSL | hsl(217, 91%, 60%) | Hue 0-360, S and L 0-100% | hsla(217, 91%, 60%, 0.5) |
| Named | tomato | Fixed keyword list | No |
Three notations, one color
HEX, RGB and HSL are different ways to write the same sRGB color. One is compact, one is literal, and one is easier to adjust by hand.
How HEX, RGB and HSL describe a color
A standard CSS color is built from three channels: red, green and blue. Each channel holds 256 possible values, from 0 to 255. Multiply the three channels and you get 16,777,216 combinations, which is why an 8-bit-per-channel color is treated as a full continuous palette.
HEX writes those three bytes in base 16, using two characters per channel. RGB writes the same three bytes in decimal. HSL rotates the model: it describes the color as a hue angle on a wheel, then how saturated that hue is and how light or dark it is. HSL does not add information that RGB lacks. It presents the same cube in a shape that is easier for a person to reason about.
| Question | HEX | RGB | HSL |
|---|---|---|---|
| Best for | Design tokens, CSS, compact config | Computed values, canvas, image data | Building palettes by hand |
| Human readable | Low | Medium | High for light and dark variants |
| Length in CSS | 4 or 7 characters | About 18 characters | About 20 characters |
| Easy to lighten | No | No | Yes, raise the L value |
A practical workflow is to pick or sample a color in HEX, adjust it in HSL, and ship it in whichever format your codebase already uses. Mixing formats inside one stylesheet is allowed, but a consistent choice makes search and replace far safer.
Converting HEX to RGB
Split the six-digit code into three pairs. Each pair is a two-digit base-16 number, so the first character is multiplied by 16 and the second is added as-is.
The letters a to f stand for 10 to 15.
channel = 16 × first digit + second digit
Take #3b82f6. The red pair 3b becomes 3 × 16 + 11 = 59.
The green pair 82 becomes 8 × 16 + 2 = 130.
The blue pair f6 becomes 15 × 16 + 6 = 246. The result is rgb(59, 130, 246).
Shorthand HEX such as #38f repeats each character: it expands to #3388ff. That is a different color from #3b82f6,
and the difference is visible when the two swatches sit side by side.
Converting RGB to HSL
HSL is derived from the same three channels. Normalize each channel to a 0-1 range, find the largest and smallest values, and work from there.
The letter L below means lightness, not luminance; the two are related but not identical.
L = (max + min) ÷ 2
S = delta ÷ (1 − |2L − 1|), with delta = max − min
H = 60 × sector value, then normalized to 0-360
For rgb(59, 130, 246) the normalized channels are 0.231, 0.510 and 0.965. The maximum is 0.965 and the minimum is 0.231, so delta is 0.733.
Lightness is (0.965 + 0.231) ÷ 2 = 0.598, or about 60%. Saturation is 0.733 ÷ (1 − 0.196) = 0.912, or about 91%.
Because blue is the largest channel, the hue uses the blue sector: (0.231 − 0.510) ÷ 0.733 + 4 = 3.620, and 3.620 × 60 = 217.2 degrees.
When delta is zero the color is a pure gray and hue is undefined, so the convention is to report hue as 0. Saturation is also 0 in that case.
This is why #808080 comes back as hsl(0, 0%, 50%) rather than some arbitrary hue.
Converting HSL back to RGB
The reverse path builds a temporary chroma value from saturation and lightness, then places it in the correct 60-degree sector of the hue wheel.
C = (1 − |2L − 1|) × S
X = C × (1 − |(H ÷ 60) mod 2 − 1|)
m = L − C ÷ 2
| Hue sector | Channel before adding m | Example hue |
|---|---|---|
| 0 to 60 | (C, X, 0) | 30 |
| 60 to 120 | (X, C, 0) | 90 |
| 120 to 180 | (0, C, X) | 150 |
| 180 to 240 | (0, X, C) | 217 |
| 240 to 300 | (X, 0, C) | 270 |
| 300 to 360 | (C, 0, X) | 330 |
Applying the formula to hsl(217, 91%, 60%) gives C = 0.728, X = 0.279 and m = 0.236.
The hue falls in the 180-240 sector, so the channels become (0, 0.279, 0.728) before m is added and each is multiplied by 255.
The rounded result is rgb(60, 131, 246). The original was rgb(59, 130, 246), so one unit per channel was lost to rounding.
Alpha channels: 8-digit HEX, rgba and hsla
CSS extends HEX with two extra digits for opacity. The order is #RRGGBBAA: alpha goes last. Android and some older tools write #AARRGGBB,
so a color copied from one platform to the other can look completely wrong even though both codes are eight digits long.
Alpha is a fraction of 255, not a percentage. A value of 80 is 128 ÷ 255, which is about 50%. Full transparency is 00 and full opacity is ff.
In rgba() and hsla() the fourth value is written as a decimal from 0 to 1.
| Alpha HEX | Decimal | Approximate opacity |
|---|---|---|
00 | 0 | 0% |
33 | 51 | 20% |
66 | 102 | 40% |
80 | 128 | 50% |
cc | 204 | 80% |
ff | 255 | 100% |
A transparent color is not a lighter color. The browser composites it over whatever is behind it, using
result = alpha × foreground + (1 − alpha) × background per channel.
The same 50% blue over white and over black produces two very different visible colors, which matters when a component can sit on more than one background.
Common color conversion mistakes
Most broken colors are not mathematical errors. They come from a value that is syntactically valid somewhere else but not in CSS, or from an alpha channel written in the wrong position.
| Mistake | What happens | Fix |
|---|---|---|
Missing # in HEX | The browser cannot parse the value | Use #3b82f6, not 3b82f6 |
| Four-digit HEX assumed to be RGB | #38f6 is read as RGBA, not as a longer color | Expand shorthand first or write six digits |
| Percentage RGB | rgb(50%, 20%, 10%) is valid; mixing percent and numbers is not | Use one unit for all three channels |
| HSL without percent signs | hsl(217, 91, 60) is invalid in CSS | Write hsl(217, 91%, 60%) |
| Saturation in 0-1 range | A near-black or near-gray color appears | Multiply by 100 for CSS |
| Alpha written first | ARGB and RGBA produce different colors | Keep alpha as the last pair in CSS |
| Rounding every step | Round-trip drift of one or two units per channel | Keep decimals until the final value |
One more trap: CSS colors are interpreted in sRGB unless you use a wider-gamut function such as color(display-p3 ...) or oklch().
A HEX value copied from a wide-gamut design file is an sRGB approximation, so the browser and the design tool may disagree slightly.
Frequently Asked Questions
#3b82f6 and rgb(59, 130, 246) are the same color.80 for 50%, or use rgba() and hsla() with a fourth value between 0 and 1. Remember that CSS puts alpha last, not first.#38f expands to #3388ff. It cannot represent #3b82f6 because the digits 3b, 82 and f6 are not repeated characters.
Rate this Tool
Based on 0 user ratings.