ChromaWell

RGB to Hex Converter

Convert RGB values (0-255 per channel) to a 6-digit hex color code — the reverse of hex-to-RGB, and just as exact, computed instantly in your browser.

HEX
#4C8DF6

How it works

Each RGB channel (0-255 in decimal) converts independently to a 2-digit base-16 pair: divide by 16 to get the first hex digit, the remainder is the second. 255 → FF, 0 → 00, 128 → 80. Concatenate the three pairs — red, then green, then blue — and prefix with # to get the final hex code. Out-of-range input (negative numbers, or values above 255) is clamped to the valid 0-255 range before conversion, since a hex digit pair can only represent that span. A subtlety worth knowing: 255 divided by 16 is 15 remainder 15, and since a single hex digit can represent 0-15, both the quotient and remainder map to 'F' — which is exactly why 255 becomes 'FF' rather than some other two-character pair, a fact that's easy to take for granted but genuinely follows from base-16 arithmetic rather than being an arbitrary convention.

Worked example

RGB(255, 99, 71) — the 'tomato' orange-red from the hex-to-RGB example above — converts back: 255 → FF, 99 → 63, 71 → 47, giving #FF6347. A pure mid-gray, RGB(128, 128, 128), converts to #808080 since each channel independently maps to the same hex pair. A less obvious case: RGB(1, 1, 1), an almost-but-not-quite-pure-black value that sometimes shows up as a rendering artifact from anti-aliasing or JPEG compression noise near a true black region, converts to #010101 — worth knowing when debugging why a supposedly '#000000 black' background is actually rendering as a barely-visible near-black in a screenshot diff tool.

When to use this tool

Use this when you're working the other direction from Hex to RGB — a JavaScript canvas API, a Python imaging library, or a data-visualization tool typically outputs colors as RGB triplets, and you need the equivalent hex string to paste into a CSS file or design tool that expects hex. It also comes up when reading pixel values directly out of an image-editing tool's eyedropper/color-sampler panel, several of which historically default to showing RGB numbers rather than hex, or when translating a data-visualization library's programmatically generated RGB color scale (d3.js color scales are a common example) into a fixed set of hex swatches for a static design deliverable. It's the same underlying conversion as the full Color Converter, just presented as a narrower, faster-to-scan single-purpose page for this one direction.

Precision & accuracy

Like hex-to-RGB, this conversion is exact — RGB and hex are the same 24-bit color value in two different bases, so there's no floating-point rounding anywhere in the pipeline, only integer-to-hex-digit formatting, which means the output is always reproducible and never varies by a shade depending on which tool or library performed the conversion. The only place 'precision' becomes a real question is upstream of this tool, at whatever step originally produced your RGB numbers — a value read off an 8-bit display buffer is already quantized to whole integers, but a value computed from, say, a linear-light blend or a gradient interpolation may arrive as a non-integer (128.7, for instance) and needs rounding to the nearest whole number before this conversion applies, since 8-bit RGB has no fractional-channel representation.

FAQ

What if my RGB values are out of range?

Values below 0 or above 255 are clamped to the valid range before conversion, so RGB(300, -10, 128) is treated as RGB(255, 0, 128).

Do I need to enter values as rgb(a, b, c) or just the numbers?

Either works — the parser accepts plain comma/space-separated numbers or the full CSS rgb()/rgba() function syntax.

Is uppercase or lowercase hex output correct?

Both are valid CSS; ChromaWell outputs uppercase by convention for readability, but hex is case-insensitive everywhere it's used.

What happens with non-integer RGB input, like 128.5?

The input is rounded to the nearest whole number before conversion, since RGB channels in the standard 8-bit color model only support integer values from 0-255.

Why is my hex output 3 characters shorter than I expected?

It isn't — this tool always outputs the full 6-digit hex form (e.g. #FF0000, not the #F00 shorthand), since the shorthand is only valid CSS when each channel pair happens to repeat the same digit twice, which most colors don't.

Can I convert percentage-based RGB, like rgb(100%, 39%, 28%)?

Yes — CSS also allows RGB channels expressed as percentages of 255 rather than 0-255 integers; the parser detects the % sign and converts each percentage to its 0-255 equivalent before the hex conversion.