Colour Converter (HEX, RGB, HSL)

Convert colours between HEX, RGB and HSL instantly, with an approximate OKLCH value for modern CSS.

Runs in your browser – nothing you type is sent anywhere.

This color converter changes a colour between HEX, RGB and HSL as you type, so you can copy whichever format your CSS, Figma file or brand guide needs. (CSS uses the American spelling color; we use “colour” in the text.)

How to use the color converter

  1. Type a colour into any field: HEX (for example #ff9933), RGB or HSL. You can also choose a colour with the colour picker.
  2. The other formats update as you type, and the swatch shows the colour so you can confirm it is the one you meant.
  3. Press a copy button to copy the value you need into your CSS or design file.
  4. Read the OKLCH line if you want a modern oklch() value. Treat it as an approximation (see below).

Different ways to write the same colour

HEX, RGB and HSL are all ways of describing a colour in the sRGB colour space, which is the standard space for the web. Here is saffron in each format:

FormatSaffronWhat the numbers mean
HEX#ff9933Three pairs of hexadecimal digits for red, green and blue, each from 00 to ff (0–255).
RGBrgb(255 153 51)Red, green and blue as numbers from 0 to 255.
HSLhsl(30 100% 60%)Hue as an angle on the colour wheel (0–360), then saturation and lightness as percentages.
OKLCHoklch(77.4% 0.163 60.3)Perceived lightness, chroma (how colourful) and hue. Approximate.

Converting HEX to RGB is simple arithmetic. Each pair is a base-16 number: ff is 15 × 16 + 15 = 255, 99 is 9 × 16 + 9 = 153, and 33 is 3 × 16 + 3 = 51.

Modern and legacy CSS syntax

Current CSS writes rgb() and hsl() with spaces between the values and an optional / before the alpha (opacity) value. The older comma syntax still works everywhere, and rgba() and hsla() are now just aliases of rgb() and hsl().

.badge {
  /* each line gives the same saffron */
  background-color: #ff9933;
  background-color: rgb(255 153 51);
  background-color: hsl(30 100% 60%);
}

.badge-soft {
  /* the same colour at 20% opacity */
  background-color: rgb(255 153 51 / 0.2);
}

.badge-legacy {
  /* older comma syntax, still valid */
  background-color: rgba(255, 153, 51, 0.2);
}

Why designers like HSL

HSL is easy to adjust by hand. Keep the hue and saturation, lower the lightness, and you have a darker shade for a hover state: hsl(30 100% 60%) becomes hsl(30 100% 45%). Add 180 to the hue to get the colour opposite on the wheel.

Watch out: HSL lightness is not how bright a colour looks. A yellow and a blue at 50% lightness look very different in brightness and give very different contrast with white text. Always check text colours with a contrast checker.

What is oklch()?

oklch() describes colour in the OKLCH space, which is designed around how people see. L is perceived lightness from 0% to 100%, C is chroma (0 is grey; values above about 0.4 are rare), and H is the hue angle. Equal steps in L look like roughly equal steps in brightness, which makes it useful for building colour scales in a design system. According to MDN, oklch() has been widely available in browsers since May 2023.

OKLCH hue numbers are not the same as HSL hue numbers. Saffron has a hue of 30 in HSL but about 60 in OKLCH, so do not copy a hue from one to the other.

Tip: The converter shows OKLCH as an approximation because the result is rounded to a few decimal places. OKLCH can also describe colours that are outside the sRGB range, which HEX cannot store. If you convert an OKLCH value back, a channel may come out one step different.

Learn more

Frequently asked questions

Is HEX or RGB better in CSS?

Neither. They describe exactly the same colours. HEX is shorter and common in design tools; rgb() makes it easy to add transparency with / 0.5. Pick one style and use it consistently.

What is an 8-digit hex code?

The last pair is alpha (opacity). For example, #ff993380 is saffron at about 50% opacity, because 80 is 128 out of 255.

Why does my colour change slightly after converting back and forth?

HSL and OKLCH values are usually rounded, and HEX can only store whole numbers from 0 to 255. Small rounding differences of one step are normal and not visible to the eye.

Can I use oklch() on a live website?

Yes. It is supported in all current major browsers. If you must support very old browsers, put a HEX or rgb() declaration first as a fallback.

More free tools

All tools

Image Compressor

Shrink JPG, PNG and WebP images in your browser. Up to 20 at a time, nothing uploaded.

Image Resizer

Resize a JPG, PNG or WebP image by pixels or percentage, with an aspect-ratio lock. Runs in your browser.

PDF Compressor

Make scanned and image-heavy PDFs smaller, right in your browser. Three levels, nothing uploaded.