Home › Converters › RGB to Hex

RGB to Hex

Your design tool, image editor or code framework shows a color as three RGB numbers, but the web page, stylesheet or design system you are feeding wants a hex code. This RGB to hex converter closes the gap: drag the red, green and blue sliders or type the values, watch the color in the live swatch, and copy the hex code with one click. It also runs in reverse — paste a hex code into the box at the bottom and the RGB values set themselves.

How it works

RGB describes a color as three channels of light: red, green and blue, each from 0 (none of that light) to 255 (the channel at full blast). Screens mix the three to make every color you see — over 16.7 million combinations in total. Hex is simply the same three numbers rewritten in base 16 and joined together: each channel becomes a two-digit pair from 00 to FF, the pairs are placed in red-green-blue order, and a # sign goes in front. Nothing about the color changes; only the notation does.

A channel converts by dividing by 16: the quotient becomes the first hex digit and the remainder the second, with the values 10 through 15 written as the letters A through F. If a channel produces a single digit — 5, for instance — it is padded with a leading zero to 05, so every pair is exactly two digits and the code is always six digits long.

Hex pair for a channel: divide the channel by 16 — quotient is the first digit, remainder is the second (10 = A, 11 = B, 12 = C, 13 = D, 14 = E, 15 = F), padded to two digits  |  Hex code = # + red pair + green pair + blue pair

The HSL figure shown under each result is a bonus view of the same color: hue is the angle on the color wheel (0–360), saturation is how vivid the color is, and lightness is how bright it is, both as percentages. Designers often adjust colors in HSL because "the same blue, but lighter" is a one-number change there, while in RGB all three channels move at once.

Worked example

A developer in Seattle is copying the accent blue from a design file into a stylesheet. The design file lists the color as rgb(37, 99, 235), and the stylesheet needs hex.

Step 1: Convert the red channel — 37 ÷ 16 = 2 remainder 5, so red is 25.
Step 2: Convert the green channel — 99 ÷ 16 = 6 remainder 3, so green is 63.
Step 3: Convert the blue channel — 235 ÷ 16 = 14 remainder 11; 14 is E and 11 is B, so blue is EB.
Step 4: Join the pairs in order behind a # sign: #2563EB.

That is exactly what the converter shows for red 37, green 99 and blue 235: #2563EB — and it happens to be the same blue this site uses for its buttons and links, with the HSL reading 221, 83%, 53% shown alongside.

Common mistakes and tips

The most common mistake is dropping the leading zero from a small channel. A channel of 5 must be written 05, not 5: rgb(255, 5, 0) is #FF0500, a six-digit code, while #FF500 would be read as a broken or entirely different color. The second trap is the 3-digit short form: #F00 is CSS shorthand for #FF0000, because each digit doubles. It only works when both digits in every pair are the same, so #2563EB has no short form.

Channel order matters too. The pairs are always red, green, blue — swapping the first and last pair turns a blue like #2563EB into the orange-brown #EB6325. And when you copy a color out of a design tool, check whether it gave you RGB or RGBA: the A is an alpha (transparency) channel from 0 to 1, and it does not belong inside a six-digit hex code — CSS writes it separately, or as two extra hex digits in the newer eight-digit form.

FAQ

What is rgb(37, 99, 235) in hex?

rgb(37, 99, 235) is #2563EB in hex. Each channel converts to a two-digit hex pair: 37 becomes 25, 99 becomes 63 and 235 becomes EB, and the three pairs join behind a # sign.

How do I convert RGB to hex by hand?

Convert each channel separately: divide by 16, write the quotient digit then the remainder digit, using A–F for 10–15, and pad a single digit with a leading zero. Then join the three pairs: red, green, blue. For 255, 128, 0 that gives FF, 80, 00 — #FF8000.

Why do RGB values stop at 255?

Each channel is stored in one byte, and a byte holds 256 possible values: 0 through 255. Zero is no light at all and 255 is the channel at full strength, so rgb(0, 0, 0) is black and rgb(255, 255, 255) is white.

What are the hex codes for black, white and pure red?

Black, rgb(0, 0, 0), is #000000. White, rgb(255, 255, 255), is #FFFFFF. Pure red, rgb(255, 0, 0), is #FF0000 — the green and blue pairs drop to 00 while red is FF.

Can I convert a hex code back to RGB here?

Yes. Type or paste a hex code into the hex box at the bottom of the converter — 6 digits like #2563EB or the 3-digit short form like #F00 — and the sliders, number boxes, swatch and HSL values all update to match.

Disclaimer: Results are conversions for guidance only. Values are rounded for display; for legal, medical, or safety-critical use, confirm with an official source or a qualified professional.