HandyBench

Color Converter

Convert HEX, RGB and HSL with live preview.

How to use the Color Converter

  1. 1 Pick a color with the picker, drag the R, G and B sliders, or type or paste a HEX value such as #3366ff.
  2. 2 See the equivalent HEX, RGB and HSL values update together.
  3. 3 Copy the CSS value you need.

How HEX, RGB and HSL relate

All three notations describe the same sRGB colour, which is why the converter can move between them without loss of meaning. A HEX code is just three bytes written in base 16: #3366FF splits into 33, 66 and FF, which are 51, 102 and 255 in decimal. A three-digit code such as #f60 is shorthand that doubles each digit, so it expands to #ff6600. RGB is the same three numbers in decimal, each from 0 to 255.

HSL is calculated from RGB. The channels are scaled to 0–1, then the converter finds the largest and smallest of them. Lightness is their average. Saturation is the gap between them divided by how far the lightness is from black or white. Hue is the angle on the colour wheel, worked out from whichever channel is largest, then multiplied by 360 and rounded. All three results are rounded to whole numbers, so HSL is shown as an integer approximation.

Worked example

For #3366ff the scaled channels are 0.2, 0.4 and 1.0. The largest is blue, the smallest is red, so lightness is (1.0 + 0.2) / 2 = 0.6, which is 60%. The gap is 0.8, and saturation is 0.8 / (2 − 1.2) = 100%. Because blue is largest, hue is (0.2 − 0.4) / 0.8 + 4 = 3.75 of 6 steps, which is 225 degrees. The converter reports hsl(225, 100%, 60%).

HEXRGBHSL
#ff0000rgb(255, 0, 0)hsl(0, 100%, 50%)
#3366ffrgb(51, 102, 255)hsl(225, 100%, 60%)
#6366f1 (the starting colour)rgb(99, 102, 241)hsl(239, 84%, 67%)
#808080rgb(128, 128, 128)hsl(0, 0%, 50%)

The grey row shows a quirk: when all three channels are equal there is no hue, so the tool reports 0 degrees and 0% saturation. Any hue would draw the same colour.

What this converter accepts and prints

  • Input: the HEX box takes 3, 4, 6 or 8 digits (#RGB, #RGBA, #RRGGBB or #RRGGBBAA), with or without the #. You can type digit by digit: the colour updates as soon as the digits form a valid value, and while the value is still incomplete the box stays as you typed it with a hint underneath. When you leave the box it reverts to the current colour. The RGB and HSL boxes are read-only; change the colour with the picker, the HEX box or the three R, G and B sliders.
  • Output: lowercase six-digit HEX, rgb(r, g, b) with comma separators, and hsl(h, s%, l%). Each has a copy button.
  • No transparency: there is no alpha channel. If you enter a 4 or 8 digit code, the alpha digits are read but ignored and the colour is shown fully opaque. Add opacity by hand, for example rgb(51 102 255 / 0.5) in modern CSS.

Choosing a format

HEX is the compact form for design hand-offs. RGB suits canvas and image code. HSL is easiest to adjust: nudge lightness by 10% for a hover state, or keep the hue and drop saturation for a muted variant. Remember that HSL lightness is not perceived brightness, so a yellow and a blue at the same L value look very different. To check whether text on a colour is readable, use the contrast checker. To build a matching set of colours, try the colour palette generator or the CSS gradient generator.

Examples

  • ▸ #3366ff = rgb(51, 102, 255) = hsl(225, 100%, 60%).
  • ▸ The shorthand #f60 expands to #ff6600.

Frequently asked questions

What is HSL and why use it?

HSL describes color by Hue, Saturation and Lightness. It makes it intuitive to create lighter/darker or more/less vivid variants of a color.

How do I convert HEX to RGB?

Split the six-digit HEX into three pairs and read each as a base-16 number. For #3366FF that is 51, 102, 255 → rgb(51, 102, 255). The converter does this instantly and both ways.

Does it support alpha (transparency)?

No. The converter works with opaque colors only. 4 and 8-digit HEX (#RGBA, #RRGGBBAA) are accepted, but the alpha digits are ignored and the color is shown fully opaque. To add transparency, append your own alpha value in CSS, for example rgb(51 102 255 / 0.5).

Can I type an RGB or HSL value to convert it?

Not directly. You can type or paste a HEX code (3, 4, 6 or 8 digits, with or without #), use the color picker, or move the R, G and B sliders. The HEX box updates as soon as the digits form a valid code and reverts to the current color when you leave it with an incomplete one. The RGB and HSL boxes are outputs, each with a copy button.

Why does a grey show hue 0 and saturation 0?

When red, green and blue are equal the color has no hue, so any angle would draw the same grey. The converter reports hue 0 and saturation 0%, with lightness showing how light the grey is.