Color converter

One color in hex, RGB, HSL and its CSS name.

loading Color converter
About this tool

What is a colour converter?

A colour can be written in many notations that describe the same point in a colour space. A web developer meets #1ea54c in a stylesheet, rgb(30, 165, 76) in a design export, hsl(140, 69%, 38%) when tweaking a shade by hand, cmyk when a printer asks for it and oklch() in modern CSS. The colour is identical; only the notation changes, and nobody wants to calculate it by hand.

This colour converter shows one colour in thirteen notations at once: a colour picker, HEX, RGB, HSL, HWB, LCH, LAB, XYZ, OKLAB, OKLCH, HSV, CMYK and the CSS colour name. Edit any field and every other one updates, so you can start from whatever you were given and copy whatever you need. It opens on #1ea54c, so the whole table is filled in from the first second.

The device-independent spaces (LAB, LCH, XYZ) and the perceptual OKLAB and OKLCH are the ones that matter for modern design work, because equal steps in lightness look equal to the eye. HSL and HSV are friendlier for choosing a shade by hand, and CMYK is what print uses. Everything is calculated in your browser, and colours are never sent to a server.

How to convert a colour

  1. Type or paste a colour in any field: for example #ff6347 in HEX, rgb(255, 99, 71) in RGB, hsl(9, 100%, 64%) in HSL or tomato in the name field. You can also pick a colour with the picker.
  2. The other fields update at once. A field with a value the tool cannot read shows an "invalid format" message, and the other fields keep the last good colour.
  3. Use the saturation and brightness sliders to change the shade without leaving the tool. They work in HSV, and a grey or black remembers its last hue, so you can bring the colour back.
  4. Press Invert for the opposite colour or Grayscale for the grey of the same luminance.
  5. Click the copy button next to the notation you need and paste it in your CSS, design tool or code.
  6. The Name field shows the nearest CSS colour name. If the match is not exact, it is shown with a tilde and the name's own hex, for instance ≈ seagreen (#2e8b57).

Notations such as lab(53.24 80.09 67.2), oklch(62.8% 0.2577 29.23) and cmyk(0%, 50%, 100%, 0%) are accepted as input too, and OKLCH and OKLAB also take a transparency after a slash (oklch(62.8% 0.2577 29.23 / 0.5)).

Examples of colour conversion

Pure red in every notation

Input #ff0000:

NotationValue
RGBrgb(255, 0, 0)
HSLhsl(0, 100%, 50%)
HWBhwb(0 0% 0%)
LABlab(54.29 80.81 69.89)
OKLCHoklch(62.8% 0.2577 29.23)
CMYKcmyk(0%, 100%, 100%, 0%)
Namered

A green from a brand palette

#1ea54c becomes rgb(30, 165, 76), hsl(140, 69%, 38%), hsv(140, 82%, 65%), cmyk(82%, 0%, 54%, 35%) and oklch(63.39% 0.1691 149.02). The nearest CSS name is ≈ seagreen (#2e8b57).

From a name to a code

tomato gives #ff6347, rgb(255, 99, 71) and hsl(9, 100%, 64%). The hex digits ff, 63, 47 are the red, green and blue channels in hexadecimal, which you can check with the base converter.

From HSL to HEX

hsl(210, 50%, 40%) gives #336699, a typical steel-blue. Lowering the lightness to 30% in HSL makes a darker shade of the same hue.

Invert and grayscale

Starting from #1ea54c, Invert gives #e15ab3 and Grayscale gives #616161. Inverting #ff0000 gives #00ffff.

Common errors and how to fix them

  • Invalid hex format. A hex colour needs 3, 4, 6 or 8 digits from 0-9 and a-f. A doubled # or a letter such as g breaks it.
  • Invalid rgb format. Write rgb(255, 99, 71) with three numbers from 0 to 255. Missing parentheses or a value above 255 are the usual causes.
  • The CMYK or LAB value does not match my design tool. CMYK here is the simple mathematical conversion from RGB, not a printer profile, so a print shop's ICC profile can give different numbers. LAB uses the D50 white point of CSS.
  • The name field shows ≈ and a different hex. No CSS name matches your colour exactly, so the nearest one is shown. Use the hex or RGB value if you need the exact colour.
  • My OKLCH colour changes slightly. Colours outside the sRGB gamut are clamped to the nearest colour sRGB can show, so converting back may not return the exact input.

Frequently asked questions

How do I convert HEX to RGB?

Split the hex into pairs and read each as hexadecimal: #1ea54c is 1e, a5, 4c, which is 30, 165 and 76. Paste the hex in the tool and copy the RGB field, or use the base converter for the individual pairs.

What is the difference between HSL and HSV?

Both describe hue, saturation and a light value, but HSL puts white at the top of the lightness scale, while HSV's brightness reaches its maximum for pure, fully bright colours. The same colour shows different saturation numbers in each, for example hsl(140, 69%, 38%) and hsv(140, 82%, 65%).

Why use OKLCH instead of HSL?

In OKLCH, changing the lightness does not shift the perceived hue or colourfulness the way HSL does, so palettes and gradients look more even. It is part of CSS Color Level 4 and supported by current browsers.

Is my colour uploaded anywhere?

No. The conversion runs in your browser.

How do I find the colours of an image?

Use image colour picker to click a pixel, or the image palette tool to extract the main colours of a photo, then paste the result here.

How to convert colours in code

JavaScript

const hex = '#1ea54c';
const [r, g, b] = hex.slice(1).match(/../g).map(h => parseInt(h, 16)); // 30, 165, 76

const toHex = (r, g, b) => '#' + [r, g, b].map(v => v.toString(16).padStart(2, '0')).join('');
toHex(255, 99, 71); // '#ff6347'

Python

colorsys uses values from 0 to 1 and returns HLS (note the order) instead of HSL.

import colorsys

r, g, b = 30 / 255, 165 / 255, 76 / 255
h, l, s = colorsys.rgb_to_hls(r, g, b)
print(round(h * 360), round(s * 100), round(l * 100))  # 140 69 38

CSS

Modern CSS accepts the new notations directly.

.button {
  background: oklch(62.8% 0.2577 29.23);   /* the red above */
  border-color: hsl(140 69% 38%);
}
Report a problem