ForHosting KIT · Images

RGB to OKLCH converter

Get the OKLCH coordinates of an RGB color: 255, 87, 51 becomes lightness 0.680358, chroma 0.210012 and hue 33.691637°. Build token ramps and palettes whose steps look even to the eye. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Resistance (Ω)
255
G
87
B
51
You get
L
0.680358
C
0.210012
H
33.691637
Oklch
oklch(0.680358 0.210012 33.691637)

This RGB to OKLCH converter turns three familiar sRGB channels into perceptually uniform cylindrical color coordinates. Enter red, green, and blue values from 0 to 255 and receive OKLCH lightness, chroma, and hue, plus a ready-to-copy CSS-style string. The calculation follows the complete deterministic path: sRGB transfer-function decoding, linear RGB to OKLab matrices, and OKLab to cylindrical OKLCH conversion. Invalid, missing, non-finite, or out-of-range channels return a clear validation error instead of silently clipping the color. It is useful for design tokens, palette analysis, color interpolation, and modern CSS workflows that need more predictable visual relationships than direct RGB arithmetic provides.

Why convert sRGB coordinates to OKLCH

RGB describes how a display combines red, green, and blue light, but equal numerical changes in those channels do not usually look equally large to a person. Increasing one channel by twenty may create an obvious shift in one region of the gamut and a subtle shift somewhere else. OKLab was designed to make coordinate distances correspond more closely to perceived color differences.

OKLCH rearranges OKLab into cylindrical coordinates that are easier to reason about: lightness describes how light or dark the color appears, chroma describes its distance from the neutral axis, and hue gives the angle around that axis in degrees. This makes OKLCH especially convenient for building token ramps, generating related colors, and comparing palette entries. The converter keeps the input contract deliberately narrow: it accepts actual sRGB channel values between 0 and 255, including fractional values, rather than attempting to guess hex strings, percentages, named colors, or wide-gamut profiles.

A narrow contract prevents an innocent formatting mistake from becoming a plausible but incorrect color. The returned hue is normalized to the range from zero up to, but not including, 360 degrees. For an achromatic color whose hue is mathematically undefined, the result uses zero as a stable deterministic convention.

How the conversion is calculated

The calculation cannot apply an OKLab matrix directly to the displayed channel numbers because ordinary sRGB values are transfer-encoded. Each input channel is first divided by 255 and decoded with the standard piecewise sRGB transfer function. Low values use the linear segment; higher values use the power function.

The three resulting linear-light components are multiplied by the fixed linear RGB to LMS matrix used by the OKLab definition. A cube root is applied to each LMS component, followed by the second fixed matrix that produces OKLab lightness and the two opponent axes conventionally called a and b. Finally, cylindrical conversion computes chroma as the Euclidean length of the a and b pair and hue with atan2, converted from radians to degrees and normalized to a positive circle.

Lightness is returned on the conventional OKLab scale from approximately zero to one for in-gamut sRGB colors, not as a percentage. Chroma has no percentage sign and depends on gamut; hue is expressed in degrees. The included oklch string uses those same values, so it can be copied or transformed without reconciling a second rounding policy.

Using the result safely in design and code

Send numeric fields named r, g, and b. Every field is required and must be finite and within the inclusive range from 0 to 255. The converter accepts fractional channel values because sampled images and intermediate color pipelines sometimes preserve more than eight-bit integer precision, but it does not accept numeric strings, NaN, Infinity, arrays, or objects in place of a channel.

OKLCH is useful for perceptual editing, but a mathematically generated color may still fall outside the gamut of a target display or export format when you later increase chroma or change lightness. This converter reports the coordinates of the supplied in-gamut sRGB color; it does not perform gamut mapping, contrast checking, alpha compositing, color-profile conversion, or accessibility certification. Use a dedicated gamut mapper after editing coordinates and a contrast tool against the actual foreground and background pair.

Because the algorithm uses no network, clock, random source, or mutable state, identical inputs produce identical output in both execution channels.

Modernize design tokens

Convert legacy RGB palette entries into OKLCH coordinates before defining perceptually organized lightness and chroma ramps.

Analyze palette relationships

Compare the lightness, chroma, and hue of existing interface colors without treating raw RGB channel distance as perceptual distance.

Prepare CSS color values

Generate a stable OKLCH string from an sRGB source color for documentation, prototypes, stylesheets, or automated token pipelines.

What RGB range does the converter accept?

Each r, g, and b channel must be a finite number from 0 to 255 inclusive. Integers and fractional values are accepted.

Is OKLCH lightness returned as a percentage?

No. The l field uses the conventional OKLab numeric scale, approximately 0 to 1 for sRGB colors. Multiply by 100 only when your destination specifically requires percentage notation.

Why is hue zero for gray, black, or white?

Hue is mathematically undefined when chroma is effectively zero. The converter returns 0 degrees as a stable deterministic convention instead of returning null or an inconsistent angle caused by floating-point noise.

Does this tool perform gamut mapping?

No. It converts an existing in-gamut sRGB color to its OKLCH coordinates. If you edit those coordinates afterward, use a gamut-mapping tool before targeting a limited color space.

Can I enter decimal channel values?

Yes. Each channel may be any number from 0 to 255, fractions included. Hex codes, percentages and color names are not guessed, and missing or out-of-range values are rejected instead of clipped.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/color/rgb-oklch

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/color/rgb-oklch \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"r":255,"g":87,"b":51}'
{
  "r": 255,
  "g": 87,
  "b": 51
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "color.rgb_oklch",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

How the conversion is calculated

The response rounds calculated coordinates to six decimal places so JSON results remain stable and readable while retaining ample precision for typical design-system work.

Using the result safely in design and code

A successful response echoes the validated channels and returns l, c, h, and a compact oklch string. API requests cost $0.002 per successful item, while the browser version runs locally.

How much does an API conversion cost?

A successful API request costs $0.002 per item. The browser converter runs locally, and invalid input returns a typed error.

Read the full KIT documentation →