Color Converter

  • Runs in your browser
  • Nothing uploaded
  • No sign-up
Input

HEX (#38f, #3b82f6, #3b82f680), rgb(), hsl() or oklch() — any of them, with or without alpha.

As text on white 3.67:1 · on black 5.70:1

Every format
HEX
#3B82F6
RGB
rgb(59 130 246)
HSL
hsl(217.2 91.2% 59.8%)
OKLCH
oklch(62.31% 0.188 259.81)
SwiftUI
Color(.sRGB, red: 0.231, green: 0.51, blue: 0.965)
UIKit
UIColor(red: 0.231, green: 0.51, blue: 0.965, alpha: 1)
AppKit
NSColor(srgbRed: 0.231, green: 0.51, blue: 0.965, alpha: 1)

sRGB → linear light (≤ 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055)^2.4) → XYZ (D65) → LMS → ∛ → OKLab → OKLCH

Conversions follow CSS Color 4. Swift output is sRGB; a Display P3 colour needs Color(.displayP3, …) and its own values.

Updated · DRISH LABS

How do you convert HEX to RGB, HSL or OKLCH?

Converting a colour between HEX, RGB, HSL and OKLCH writes the same colour in another notation, and a free browser tool can also give it as SwiftUI, UIKit and AppKit code. OKLCH describes perceived lightness, chroma and hue, so equal changes in its lightness look equal, which HSL lightness does not. An OKLCH colour outside sRGB is brought inside by reducing chroma while keeping lightness and hue. Alpha carries through every format.

How it works

  1. Type or paste a colour in any common form — #38f, #3b82f6, #3b82f680, rgb(59 130 246), rgba(59, 130, 246, 0.5), hsl(217 91% 60%) or oklch(62% 0.19 260) — or pick one with the colour picker.
  2. Every other form appears beside it at once: HEX, RGB, HSL and OKLCH in modern CSS syntax, plus the same colour as SwiftUI, UIKit and AppKit initialisers. Each line copies with one press.
  3. Alpha is carried through every format: an eight-digit hex, a slash in rgb() or hsl(), an opacity in SwiftUI.
  4. An OKLCH colour outside the sRGB gamut is brought inside the way a browser does it — chroma reduced until it fits, lightness and hue held — and the page says that the values shown are the mapped colour.
  5. Underneath, a quick check of the colour as text on white and on black. Everything runs in the page.

How HEX becomes OKLCH

Each 8-bit channel is divided by 255, then linearised — the sRGB transfer function undoes the gamma that screens apply. The linear values go through a fixed matrix to CIE XYZ, then through Björn Ottosson’s matrices to LMS cone responses, a cube root, and a final matrix to OKLab: lightness L and the opponent axes a and b. OKLCH is OKLab in polar form: chroma is the distance from grey, hue is the angle. Because OKLab is built so that equal steps look equal, OKLCH lightness predicts how light a colour actually looks far better than HSL lightness, which calls pure yellow and pure blue equally light.

c ≤ 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055)^2.4 → XYZ → LMS → ∛ → OKLab (L, a, b) → C = √(a² + b²), h = atan2(b, a)

When you need it

A hex from a design file into SwiftUI
Paste the hex from Figma or Sketch and copy the SwiftUI line — Color(.sRGB, red: 0.231, green: 0.51, blue: 0.965). Three decimals is finer than one 8-bit step, so the colour on device is the one in the design.
Reading a Tailwind v4 theme
Tailwind v4 writes its palette in oklch(). Paste one to see its hex for a tool that does not speak OKLCH yet, or to match it in an app.
Building a tint scale by lightness
Convert the brand colour to OKLCH, change only the lightness, and convert back. Steps in OKLCH lightness look evenly spaced, which steps in HSL lightness do not.
Moving old CSS to modern syntax
rgba(0, 0, 0, 0.5) becomes rgb(0 0 0 / 0.5) and the eight-digit #00000080 — the forms current CSS and design tools use.

Questions

What is OKLCH?

A way of writing colour as perceived lightness (L), chroma (C, how far from grey) and hue (H, an angle), defined in CSS Color 4 and supported in every current browser. Unlike HSL, equal changes in its lightness look equal, which makes it the better space for building palettes and adjusting colours.

Why did my OKLCH colour change when converted?

Because it lay outside sRGB, the gamut a hex code can describe. OKLCH can name colours only wide-gamut displays show; to write one as hex it has to be brought inside, which this page does the way CSS Color 4 specifies — reducing chroma while keeping lightness and hue — and says when it happened.

Which SwiftUI, UIKit and AppKit initialisers does it write?

Color(.sRGB, red:green:blue:), UIColor(red:green:blue:alpha:) and NSColor(srgbRed:green:blue:alpha:). Each names sRGB unambiguously, so the colour matches the hex. A Display P3 colour needs Color(.displayP3, …) with P3 values instead.

Does it handle transparency?

Yes. Alpha is read from #RRGGBBAA, #RGBA, rgb(… / a), rgba(), hsl(… / a) and oklch(… / a), and written into every output — including opacity in SwiftUI and alpha in UIKit and AppKit.

Why does HSL say two colours are equally light when they clearly are not?

HSL lightness is a formula on the RGB numbers, not a measure of perception: hsl(60 100% 50%) yellow and hsl(240 100% 50%) blue both have 50% lightness. OKLCH lightness is designed to match what the eye sees, which is why the OKLCH line is there.

Is anything uploaded?

No. The conversions run in your browser as you type.

Keep going

All 31 tools