Developer Tools

Color Converter

Convert colours between HEX, RGB, HSL and OKLCH, with copy-ready CSS and a readable text colour.

By Nitin Raturi · Last reviewed

Input

How to use the Color Converter

Convert a colour between HEX, RGB, HSL and OKLCH, ready to paste into CSS.

  1. Type or paste a colour, or pick one.
  2. Read it in every format.
  3. Copy the CSS value you need.
  4. Check the suggested text colour for readable labels on it.

Good to know

  • Tap the ⓘ next to the field for accepted formats.

Converts between HEX, RGB, HSL and OKLCH using the CSS Color Level 4 formulas.

Runs in your browser. Nothing you type is uploaded or saved in the link.

Colour

Any CSS colour in hex, rgb() or hsl() form, with or without transparency.

How to fill it in

  • Type #0f766e, #0f7, rgb(15 118 110), rgb(15, 118, 110, 0.5) or hsl(175 77% 26%).
  • Or use the colour picker beside the field.

Example

#0f766e is rgb(15 118 110), hsl(175.3 77.4% 26.1%) and oklch(51.09% 0.0861 186.39).

Result

HEX

#0f766e

RGB

rgb(15 118 110)

HSL

hsl(175.3 77.4% 26.1%)

OKLCH

oklch(51.09% 0.0861 186.39)

Contrast on white
5.47:1
Contrast on black
3.83:1
Readable text on it
White

How this calculator works

  1. Step 1Read the colourHEX, RGB or HSLAny common CSS form, with optional transparency.
  2. Step 2Convert through sRGB0–255 per channelEvery format describes the same red, green and blue light.
  3. Step 3Write every formatCopy-ready CSSHEX, rgb(), hsl() and oklch().

HEX and RGB say how much red, green and blue light to mix. HSL and OKLCH describe the same colour as hue, colourfulness and lightness, which is easier to adjust by eye.

Worked example: a teal

#0f766e has 15 red, 118 green and 110 blue.

Converting #0f766e
Hex pairs to numbers
0f 76 6e (base 16)
  1. RGBrgb(15 118 110)
  2. Hue (angle on the colour wheel)175.3°
  3. Saturation77.4%
  4. Lightness26.1%
  5. HSLhsl(175.3 77.4% 26.1%)

Reading the result

  • HSLSimple mathsSame lightness number can look very different across hues.
  • OKLCHMatches the eyeEqual lightness values look equally light, so palettes stay even.
  • HEXShort and universal: #0f766e, or #0f766e80 with alpha.
  • RGBThree numbers 0–255; modern CSS separates them with spaces.
  • HSLHue in degrees, saturation and lightness in %.
  • OKLCHPerceptual lightness, chroma and hue, supported by current browsers.

A colour can be written several ways. Whether text on it is readable is a separate check.

To test text against a background, use the color contrast checker, which follows WCAG 2.2. For hex arithmetic, try the hex calculator.

Common mistakes

  • Mistake: Making a lighter shade by raising HSL lightness alone.

    Instead: Try OKLCH lightness for steps that look even.

  • Mistake: Picking text colour by eye.

    Instead: Check the contrast; use the suggested black or white.

  • Mistake: Dropping the alpha when copying.

    Instead: Copy the full value; the converter keeps transparency.

Read how we test our calculators, or browse more developer tools.

Frequently asked questions

Are HEX and RGB the same colour?

Yes. A hex code writes the same red, green and blue numbers in base 16. #0f766e is rgb(15 118 110).

What is OKLCH?

A colour format based on how people perceive lightness. Colours with the same OKLCH lightness look equally light, which helps build even palettes. Current browsers support it in CSS.

Why do I get decimals in HSL?

Most hex colours do not land on whole-number hue, saturation and lightness values. The converter shows one decimal so the value converts back accurately.

Does it keep transparency?

Yes. An alpha value in the input, such as #0f766e80 or rgb(15 118 110 / 0.5), is kept in every output format.

Can I type colour names like “teal”?

Not yet. Use a hex code, rgb() or hsl(), or pick the colour with the colour picker.

Sources and methodology

The formulas are standard time-value-of-money results. We check every figure against golden values worked out independently, by closed form and by month-by-month simulation; see the methodology.

Written and maintained by Nitin Raturi, a software engineer (about the author). Last reviewed 27 Oct 2026; next review due by . Found an error? Tell us.

Changelog

  • : Initial release. Demand metrics remain unverified.