Color Converter

Convert colors between HEX, RGB, and HSL with a live preview

About Color Converter

Paste a color in HEX, RGB or HSL and the tool detects the format and shows all three. It accepts three-digit shorthand like #fff, the modern space-separated CSS syntax rgb(255 0 0), and even a bare 255, 128, 0. Values with an alpha channel (#rrggbbaa) are accepted, but the alpha is dropped and only the color is converted.

All three formats describe the same sRGB color space. HEX and RGB carry exactly the same information; HSL rearranges that RGB into an angle on the color wheel, a saturation and a lightness. The math is simple. What trips designers up is that HSL's lightness is not the brightness people actually see.

50% lightness in HSL is not equal brightness

Yellow #ffff00 is hsl(60, 100%, 50%); blue #0000ff is hsl(240, 100%, 50%). Same L, yet on screen the yellow is glaring and the blue is dark. HSL's L is just the average of the largest and smallest channel, so it ignores the fact that human vision is most sensitive to green and least sensitive to blue.

The relative luminance WCAG uses for contrast ratios weights linearized R, G and B by 0.2126, 0.7152 and 0.0722. By that measure yellow is about 0.93 and blue about 0.07. If you build a set of button colors by keeping L fixed and rotating the hue, white text will be readable on some and unreadable on others for exactly this reason.

How HSV and OKLCH differ

This tool handles HEX, RGB and HSL only. HSV (also called HSB), common in graphics-app color pickers, shares HSL's hue angle but defines its brightness axis as the largest channel value. So pure red is L 50% in HSL but V 100% in HSV. The saturation value also uses a different formula in each model, so an S of 100% does not mean the same thing.

OKLCH is the cylindrical form (lightness L, chroma C, hue H) of Oklab, a color space published by Björn Ottosson in 2020 and adopted into CSS Color Level 4 as the oklch() function. Its L is designed to track perceived lightness: yellow comes out near 97%, blue near 45%. Keep L fixed and rotate H, and the colors stay roughly equally bright, which is the main thing HSL cannot do. This tool does not convert to OKLCH.

The sRGB gamut and what HEX cannot express

HEX and 0–255 rgb() values can only describe colors inside the sRGB space (IEC 61966-2-1). Many current phones and laptops can display the wider Display P3 gamut, and the most saturated greens and reds there have no HEX equivalent. In CSS you need color(display-p3 …) or oklch() to reach them.

Each channel has 8 bits, so 256 steps. If HSL were rounded to whole numbers, HEX → HSL → HEX would not always return the original value, so this tool shows HSL to one decimal place. Checked against all 16.7 million sRGB colours, one decimal is enough for every one of them to come back to the same HEX. HSL written as whole numbers elsewhere has already been rounded, so it can still land a channel one step away.

Practical uses of HSL anyway

HSL is still handy for quick adjustments: lowering S desaturates toward gray, raising L moves toward white. It is fine for hover states and tints of a single hue. It is the wrong tool for building a multi-hue palette with consistent contrast, where you should check contrast ratios directly or work in OKLCH.

Worked examples

Basic conversion

Input
#3366CC
Output
rgb(51, 102, 204) / hsl(220, 60%, 50%)

0x33 = 51, 0x66 = 102, 0xCC = 204. The largest channel is 0.8 and the smallest 0.2; their average 0.5 gives L = 50%.

Same L, different brightness

Input
#ffff00 and #0000ff
Output
hsl(60, 100%, 50%) / hsl(240, 100%, 50%)

Both have L = 50%, but relative luminance is about 0.93 versus 0.07, more than ten times apart.

A lossless round trip

Input
#1A2B3C
Output
hsl(210, 39.5%, 16.9%)

Feed that HSL string back in and you get #1a2b3c. The integer version hsl(210, 40%, 17%) would give #1a2b3d, with the blue channel one step off.

Bare numbers

Input
255 128 0
Output
#ff8000 / hsl(30.1, 100%, 50%)

Three plain numbers are treated as RGB.

How to use it

  1. Paste a HEX, rgb() or hsl() value as you have it.
  2. Check the three converted values and the preview swatch.
  3. Copy the format you need.

Frequently asked questions

Does it support 8-digit HEX (#RRGGBBAA)?

It accepts it, but drops the alpha channel and converts only the color.

Why does converting HSL back to HEX change the value slightly?

The HSL this tool outputs (one decimal place) converts back to the original HEX exactly. If you type a whole-number HSL such as hsl(210, 40%, 17%), a channel can shift by about one step.

Can I get OKLCH or HSV values?

No. The tool covers HEX, RGB and HSL only.

Two colors have the same lightness but different contrast. Why?

HSL lightness is the midpoint of the largest and smallest channels, not perceived brightness. Judge contrast with WCAG relative luminance.

Related guides

Sources

Last reviewed:

Privacy and how data is handled