🎨 Color Space Studio

Color Converter (HEX, RGB, HSL & CSS)

Convert a HEX code or picked color, including alpha, to CSS-ready RGB and HSL values with a live preview and one-click copy.

Accepts 3, 4, 6 or 8 hex digits; the 4th and 8th digits set transparency (alpha).

HEX Code
#6366f1
RGB Color
rgb(99, 102, 241)
HSL Color
hsl(239, 84%, 67%)

Three notations for the same sRGB colour

HEX and RGB are two spellings of the same thing. A hex code such as #6366f1 is three pairs of base-16 digits, one each for red, green and blue, and each pair runs from 00 to ff, which is 0 to 255 in decimal. The three-digit shorthand doubles each digit, so #f60 means #ff6600.

HSL describes the colour differently: a hue angle from 0 to 360 degrees around the colour wheel, a saturation percentage for how far it is from grey, and a lightness percentage from black to white. It is calculated from the largest and smallest of the three RGB channels, which is why it is handy for building lighter and darker variants of one brand colour.

Worked conversion: #6366f1 to RGB and HSL

Split the hex code into 63, 66 and f1. In decimal those are 99, 102 and 241, so the RGB form is rgb(99, 102, 241).

For HSL, scale each channel to the range 0 to 1. The maximum is 241/255 and the minimum is 99/255. Lightness is their average, 340/510, or 66.7 percent. Because lightness is above 50 percent, saturation is the difference divided by (2 minus max minus min), which is 142/170, or 83.5 percent. Blue is the largest channel, so hue is 60 x ((99 - 102) / 142 + 4), which is about 238.7 degrees. Rounded, the result is hsl(239, 84%, 67%).

That rounding matters. Converting hsl(239, 84%, 67%) back to RGB gives rgb(100, 103, 242), one step away from the original on every channel. Keep the hex or RGB value as the source of truth in a design system and treat rounded HSL as a derived convenience.

Which format to use in CSS

Hex codes are compact and are what most design tools export, so they suit design tokens and style guides. The rgb() function is easier to read when you need transparency, written in modern CSS as rgb(99 102 241 / 0.5).

HSL shines when you generate shades: keep the hue and saturation and step the lightness for hover states, borders and backgrounds. Be aware that HSL lightness is not perceptual. Yellow and blue at the same 50 percent lightness look very different in brightness, so for evenly spaced palettes many teams now reach for oklch(), which CSS Color Level 4 supports in current browsers.

What this converter does not cover

The input accepts 3, 4, 6 and 8-digit hex codes, with or without the leading #. The 4-digit and 8-digit forms carry an alpha channel, which is shown as rgba() and hsla(); the colour picker swatch ignores alpha because browsers' native pickers are opaque. Anything else, such as 5-digit codes, stray characters or CSS named colours like rebeccapurple, is rejected with a message rather than guessed at.

It also does not measure contrast. If the colour will hold text, check it against its background with a WCAG contrast checker: body text needs a ratio of at least 4.5:1 and large text at least 3:1 to meet level AA.

Color Converter (HEX/RGB/HSL): frequently asked questions

Why does converting HSL back to HEX give a slightly different colour?

HSL values are usually rounded to whole degrees and percentages, which throws away a little precision. Converting back can land one or two steps away on each RGB channel, as with #6366f1 returning as rgb(100, 103, 242). The difference is rarely visible, but it can break exact matches in tests or design tokens.

Are HEX colour codes case sensitive?

No. #6366F1 and #6366f1 are the same colour in CSS and in every major design tool. Pick one style, usually lowercase, and keep it consistent so search and diff tools find every use.

How do I add transparency to a HEX colour?

Append a fourth pair for alpha, from 00 (fully transparent) to ff (opaque). For about 50 percent opacity use 80, since 128/255 is roughly 0.5, giving #6366f180. Alternatively write rgb(99 102 241 / 0.5), which is easier to read.

What does 0% saturation mean in HSL?

It is a pure grey, and the hue value no longer has any effect. #808080 converts to hsl(0, 0%, 50%), and changing the hue to 200 or 300 would still give the same grey.

Why does the same HEX colour look different on my phone and in print?

Hex codes describe colours in the sRGB space, and screens vary in calibration, brightness and colour gamut. Print uses CMYK inks, which cannot reproduce some bright sRGB colours at all. For print work, ask the printer for the CMYK or Pantone equivalent rather than relying on the hex value.

All developer utilities & crypto