How to Convert RGB to HEX
Enter red, green and blue channels and copy the hexadecimal result. Each channel becomes a two-digit hexadecimal pair. Verify the preview so a mistyped value does not silently change the intended color.
RGB Channel Values From 0 to 255
Channels range from 0 to 255 and this interface clamps values to that range. Fractional values are rounded for byte output. Check incoming values rather than relying on clamping to diagnose an upstream error.
HEX Color Formatting
A full RGB HEX color has a hash followed by six digits. Zero-padding preserves two digits per channel. Letter case does not change the represented color; this tool displays uppercase HEX.
RGB to HEX Examples
RGB 37, 99, 235 becomes #2563EB. RGB 0, 0, 0 is #000000 and 255, 255, 255 is #FFFFFF. Optional alpha adds another pair and does not replace any channel.
Using HEX Colors in CSS
Use the copied code in CSS color properties and design tokens. When introducing alpha, test the composited result over the intended background. A numeric conversion alone does not establish accessible contrast.
More examples and technical details
How to Convert RGB to HEX by Hand
Going from RGB to HEX is the reverse trip: you take three decimal channel values, each between 0 and 255, and rewrite each one as a two digit base 16 number. Stick the three results together, add a hash in front, and you have a HEX code.
The steps:
- Take the red value and divide by 16. The whole number is the first hex digit, the remainder is the second.
- Do the same for green, then blue. Values 10 through 15 are written as A through F.
- Concatenate the three two digit results in red, green, blue order.
- Add a leading hash to finish the code.
Worked example: rgb(255, 87, 51)
Always Pad to Two Digits
The one thing people get wrong is dropping a leading zero. Every channel must become exactly two hex characters. A red value of 5 converts to 05, not 5, because a HEX code is read in fixed pairs. If you wrote #553 instead of #050503 the browser would read it as a completely different color, or as an invalid shorthand. When a channel converts to a single digit, pad it with a leading zero before joining the pairs.
Why Designers and CSS Prefer HEX
If RGB gives you the raw numbers, why convert back to HEX at all? Convenience. A HEX code is a single compact token, seven characters including the hash, that you can copy, paste, and share without commas, spaces, or a function wrapper. Design tools, style guides, and CSS variables almost all default to HEX because one string is easier to pass around than three separate numbers. It also reads cleanly in a diff and slots straight into a color swatch. RGB earns its keep when you are doing math on the channels, but for storing and communicating a fixed color, HEX is the tidier choice, which is why it remains the lingua franca of web color.
Named Color Reference
CSS ships with a set of keyword colors you can write by name instead of a code. They map to exact HEX and RGB values, so the table below is handy when you want to sanity check a conversion or reach for a familiar color without opening a picker.
| Name | HEX | RGB |
|---|---|---|
| black | #000000 | rgb(0, 0, 0) |
| white | #FFFFFF | rgb(255, 255, 255) |
| red | #FF0000 | rgb(255, 0, 0) |
| green | #008000 | rgb(0, 128, 0) |
| blue | #0000FF | rgb(0, 0, 255) |
| yellow | #FFFF00 | rgb(255, 255, 0) |
| cyan | #00FFFF | rgb(0, 255, 255) |
| magenta | #FF00FF | rgb(255, 0, 255) |
| silver | #C0C0C0 | rgb(192, 192, 192) |
| gray | #808080 | rgb(128, 128, 128) |
| orange | #FFA500 | rgb(255, 165, 0) |
| purple | #800080 | rgb(128, 0, 128) |
| teal | #008080 | rgb(0, 128, 128) |
| navy | #000080 | rgb(0, 0, 128) |
Need a different color task? Browse every free developer tool including color converters, encoders, and hashing utilities.
Frequently asked questions
How do I convert RGB to HEX?
Convert each 0–255 channel to two hexadecimal digits and join the three pairs, or use the tool.
What happens when an RGB value is outside 0–255?
The interface clamps it into range. Correct the source value if clamping was not intended.
Does the output use uppercase or lowercase hex?
The tool displays uppercase hexadecimal letters; lowercase represents the same color.
Can I convert alpha values too?
Yes. Adjust alpha to obtain a transparency-aware value.
Is conversion client-side?
Yes. No server conversion is needed.