ForHosting KIT · Images

XYZ to hex converter

Enter X, Y and Z and get the screen color as a hex code: 0, 0 and 0 give pure black, #000000. Values a screen cannot show are brought to the nearest displayable color instead of failing. 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
X
0
Y
0
Z
0
You get
Resistance (Ω)
0
G
0
B
0
Hex
#000000

This XYZ to hex converter accepts three CIE 1931 tristimulus numbers—X, Y, and Z—and returns a deterministic six-digit sRGB hex color under the D65 white point used on the web. The engine multiplies by the inverse of the standard D65 sRGB-to-XYZ matrix, clamps any linear channel that falls outside the unit cube (true out-of-gamut stimuli map to the nearest displayable edge), applies IEC 61966-2-1 gamma encoding, packs 0–255 channels into lowercase hex, and never calls the network, samples randomness, or reads the clock.

What XYZ to hex conversion means and what you get

CIE XYZ is a device-independent tristimulus space built so that Y tracks relative luminance and X and Z carry the remaining spectral stimulus. Web and most consumer displays speak sRGB instead: three gamma-encoded eight-bit channels packaged as a hash and six hexadecimal digits. Bridging those worlds requires a fixed illuminant and primaries—here illuminant D65 and the sRGB primaries codified in IEC 61966-2-1.

Relative XYZ is the usual web convention: diffuse white sits near Xn equals 0.95047, Yn equals 1.0, Zn equals 1.08883, and pure black is the origin. This calculator multiplies your X, Y, and Z by the inverse of the D65 sRGB matrix to obtain linear red, green, and blue light. Any linear channel below zero or above one is clamped to the unit interval so out-of-gamut spectra still produce a defined screen color instead of negative bytes or NaN.

Gamma encoding then maps linear light to the non-linear sRGB curve, channels scale by two hundred fifty-five and round to integers, and the six nibbles form #RRGGBB. There is no silent NaN-to-black path and no alternate white point on this page: if you need Adobe RGB, ProPhoto, or Lab packaging, use a dedicated tool.

Where an XYZ to hex converter fits in design, science, and software

Display calibration labs convert spectrophotometer XYZ readings into sRGB hex for quick visual checks against brand swatches and UI mocks. Color-management pipelines that already store intermediate XYZ under D65 need a last mile to CSS tokens without pulling a full ICC engine into a serverless function. Accessibility and design-system teams document measured or computed XYZ for brand reds and neutrals, then publish the clamped sRGB hex that ships in the product so engineering and marketing share one string.

Students meet this mapping in computer-graphics and color-science courses after learning XYZ and before implementing gamma and hex packing; a deterministic oracle lets them check homework without opaque desktop calculators. Pair it with RGB-to-Lab or hex-to-RGB tools when you need the reverse or a perceptual intermediate, and with other free deterministic converters when you are building a small lab for color hygiene.

Lab and display calibration notes

Turn measured or computed CIE XYZ under D65 into CSS #RRGGBB for visual checks, brand tokens, and calibration reports.

Homework and teaching demos

Check student XYZ-to-sRGB work and live-demo gamut clamping without opaque calculator apps.

What does the XYZ to hex converter cost?

It is free in your browser on this page.

What white point and primaries does this use?

Illuminant D65 with the standard sRGB primaries (IEC 61966-2-1).

What happens if XYZ is outside the sRGB gamut?

Linear RGB channels are clamped to [0, 1] before gamma encoding. The response sets clamped to true when any channel was clamped, and still returns a valid six-digit hex.

What XYZ values give white?

On the usual relative scale, diffuse white sits near X 0.95047, Y 1.0 and Z 1.08883 under D65. Values close to those return a near-white hex code, while 0, 0 and 0 returns pure black.

Is the hex code uppercase or lowercase?

The main result is a lowercase six-digit code with a hash, such as #000000, ready for web pages. An uppercase copy and a version without the hash are also given, so you can paste whichever your tool expects.

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/xyz-hex

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/xyz-hex \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"x":0.4124564,"y":0.2126729,"z":0.0193339}'
{
  "x": 0.4124564,
  "y": 0.2126729,
  "z": 0.0193339
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "color.xyz_hex",
  "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.

Missing or non-finite components fail with invalid_input instead of inventing a color.

What CIE XYZ to hex conversion means and what the response contains

The engine either builds a six-digit hex for three finite tristimulus numbers or rejects the request with invalid_input.

How X, Y, and Z are read, validated, and converted reproducibly

There is no absolute range check on X, Y, or Z themselves: measured spectra can produce values outside the sRGB cube, and the contract is to clamp the derived linear RGB rather than refuse the measurement. After validation, conversion is closed-form arithmetic only: three multiply-adds per channel for the inverse matrix, three clamps, three gamma branches, three scales and rounds, then nibble packing with a fixed digit alphabet. Pure black XYZ zero maps to #000000 with clamped false; D65 white maps to #ffffff; a pure red stimulus near the sRGB red primary maps to #ff0000. Tiny floating-point overshoots just outside zero or one are clamped like any other out-of-gamut sample so goldens stay deterministic across runtimes. The preferred fields are lowercase x, y, and z, but capital X, Y, and Z aliases are accepted so instrument logs, spreadsheets, and typed forms can reuse column names without renaming. Outer whitespace on string numbers is trimmed; JSON numbers and numeric strings both work. Empty strings after trim, missing fields, objects, arrays, Infinity, and NaN fail with a message that names the field and states that a finite CIE XYZ tristimulus number is required—those failures use invalid_input and are not billed. Pair the free browser run on this page with the priced API when you need the identical mathematical result inside an automated pipeline.

Where an XYZ to hex converter fits in design, science, and software

On this page the work runs entirely in your browser; through the API each successful conversion costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split—free interactive exploration and a priced, identical API—matches the rest of the KIT tier-A catalog and lets you move from a lab notebook or design review to an automated pipeline without changing the mathematical result.

Deterministic design-token fixtures

Generate reproducible hex strings from XYZ columns for unit tests, CI goldens, and design-system pipelines.

Which fields are required?

Finite numbers x, y, and z (aliases X, Y, Z). Missing fields, empty strings, Infinity, and NaN are rejected with invalid_input.

Is the hex uppercase or lowercase?

The primary hex field is lowercase with a leading # (for example #ff0000). hex_no_hash omits the hash; uppercase returns the #RRGGBB form with A–F.

Read the full KIT documentation →