RGB to Hex Converter

Type or paste RGB values, or rgb(255, 99, 71), and get the matching hex code instantly, plus the same colour in HSL, HSV and CMYK if you need it.

Files never leave your device
hex#ff6347
rgbrgb(255, 99, 71)
hslhsl(9, 100%, 64%)
hsvhsv(9, 72%, 100%)
cmykcmyk(0%, 61%, 72%, 0%)

Turning three decimal numbers into hex pairs

Going from RGB to hex is the mirror of hex to RGB: instead of splitting a string into pairs and reading each as base-16, you take three decimal numbers and write each one as a two-digit hexadecimal number, then concatenate the results. Every step is per-channel — red becomes its own pair, green becomes its own pair, blue becomes its own pair — and the three pairs are simply placed next to each other with a # in front.

Two worked examples

Take rgb(30, 144, 255). Convert 30: it is 1 × 16 + 14, and 14 in hex is e, so 30 is 1e. Convert 144: it is 9 × 16 + 0, so 144 is 90. Convert 255: it is 15 × 16 + 15, the maximum for a byte, so 255 is ff. Joined, that is #1e90ff — dodger blue.

A second example, rgb(46, 204, 113): 46 is 2 × 16 + 14, which is 2e; 204 is 12 × 16 + 12, which is cc; 113 is 7 × 16 + 1, which is 71. The result is #2ecc71, a clean emerald green. Both examples are the reverse of a hex-to-RGB conversion, and running either one back through the other direction returns the original numbers exactly, with no rounding drift in either direction.

Tip: If you already know the hex code you're aiming for, working in the other direction can be faster to sanity-check: #ff6347's pairs, ff/63/47, are 255/99/71 — the same tomato red rgb(255, 99, 71) converts back to.

Why 255 is a ceiling, not a suggestion

An 8-bit colour channel has exactly 256 possible values, 0 through 255, because a byte holds 256 distinct states. rgb(255, 99, 300) is not a very bright, very saturated red — it is a number that has no hex pair to become, since two hex digits stop at ff. Tools that silently clamp 300 down to 255 hide the fact that a value came from somewhere else entirely: a 0–100% scale mistyped as 0–255, a value doubled by a unit-conversion bug, or a paste that grabbed one digit too many. Flagging the input instead of guessing keeps that bug visible. The same logic applies at the bottom end: a negative channel, like rgb(-10, 99, 71), is rejected for the same reason — there is no hex pair below 00, so a negative number is not a darker shade, it is a value that should never have reached this step.

Tip: Getting an out-of-range error on a colour you copied from code? Check whether the source used a 0–100% or 0–1 scale for that channel — multiplying by 255 (or by 2.55 for a percentage) usually recovers the number this tool expects.

Decimal to hex, quick reference

A handful of round numbers are worth recognising on sight, since they come up constantly in design tools and default palettes.

DecimalHex pair
000
1610
3220
6440
12880
255ff

When hex is the better format to hand off

RGB is what a colour picker or a canvas API tends to give you; hex is what a stylesheet, a design handoff document, or a Slack message asking "what colour is this" tends to want. Converting RGB to hex is the step that turns three numbers scattered across a UI into one string a designer or a CSS rule can use directly, which is why the two conversions get used about equally often in practice — the direction just depends on which end of the pipeline you're standing at. Keep both this page and its Hex to RGB counterpart bookmarked and you cover the pipeline in either direction, whichever end a colour happens to arrive from.

Frequently asked questions

How do I turn RGB numbers into a hex code by hand?
Convert each channel to hex separately, then join the three pairs. 30 in hex is 1e, 144 is 90, and 255 is ff, so rgb(30, 144, 255) becomes #1e90ff. There is no rounding or blending between channels — each one maps to exactly two hex digits on its own.
Why does the tool reject rgb(255, 99, 300)?
Because 300 cannot be one channel of a colour. A byte — two hex digits — tops out at 255 (ff), so there is no hex pair 300 could become. The input is refused rather than silently trimmed, because guessing whether you meant 30, 200 or 255 would just hide the typo.
Is a channel above 255 the same as a brighter colour?
No — screens do not get brighter past 255, so there is nothing for a larger number to mean. 255 is already full intensity for that channel; a value above it is not a more vivid red, it is invalid input, almost always a stray digit or a value meant for a 0–100% scale.
Can RGB channels be negative or fractional?
Not in this format. CSS rgb() channels are integers from 0 to 255 inclusive. A negative number or a decimal like 99.5 does not correspond to any hex pair, so both are rejected the same way an out-of-range value is.
Do percentages work instead of 0–255 numbers?
Yes — rgb(100%, 39%, 28%) is valid CSS and converts the same way, by first scaling each percentage back to a 0–255 value before it is turned into hex. Mixing a percentage with a plain number in the same colour is not valid, though, so keep all three channels in one style.
Does the output hex use uppercase or lowercase letters?
Lowercase, which is the more common convention in stylesheets and version control diffs. Hex is case-insensitive to every parser, including this one, so #1E90FF and #1e90ff are the same colour if you need uppercase for a design tool.
What happened to my alpha value when I copied the hex?
If your RGB had an alpha channel below 1, look for an 8-digit hex output rather than the usual 6 — the extra pair at the end encodes opacity. A 6-digit hex code cannot carry alpha at all, so full transparency information is only preserved in the 8-digit form.