RGB to HEX Color Converter
Enter the RGB color values to convert to hex or Hex to RGB.
#FF5733
Hex Color โ RGB Breakdown
Red
255
Green
87
Blue
51
What does this RGB to Hex converter do?
It takes input in the form of values for Red, Green and Blue ranging from 0 to 255 and then converts those values to a hexadecimal string that can be used to specify color in HTML/CSS code. Photo editing software usually represents color in RGB and therefore if you would like to use the colors you use in your photo editing software as the background of your HTML element then you will have to get the hexadecimal representation of the RGB values. This tool allows you to get those values.
How to Convert RGB to Hex
- Get the Red, Green, and Blue color values (each 0-255)
- Convert each decimal value to a 2-digit hexadecimal number
- Concatenate the 3 hex values with a # prefix
Formula
Hex = "#" + R.toString(16).padStart(2, "0") + G.toString(16).padStart(2, "0") + B.toString(16).padStart(2, "0")
Example
RGB: (255, 87, 51)
Red: 255 = 15ร16 + 15 = FFโโ
Green: 87 = 5ร16 + 7 = 57โโ
Blue: 51 = 3ร16 + 3 = 33โโ
Result: #FF5733
RGB to Hex Color Table
| Color Name | RGB | Hex | Preview |
|---|---|---|---|
| Black | 0, 0, 0 | #000000 | |
| White | 255, 255, 255 | #FFFFFF | |
| Red | 255, 0, 0 | #FF0000 | |
| Lime | 0, 255, 0 | #00FF00 | |
| Blue | 0, 0, 255 | #0000FF | |
| Yellow | 255, 255, 0 | #FFFF00 | |
| Cyan | 0, 255, 255 | #00FFFF | |
| Magenta | 255, 0, 255 | #FF00FF | |
| Silver | 192, 192, 192 | #C0C0C0 | |
| Gray | 128, 128, 128 | #808080 | |
| Maroon | 128, 0, 0 | #800000 | |
| Olive | 128, 128, 0 | #808000 | |
| Green | 0, 128, 0 | #008000 | |
| Purple | 128, 0, 128 | #800080 | |
| Teal | 0, 128, 128 | #008080 | |
| Navy | 0, 0, 128 | #000080 | |
| Orange | 255, 165, 0 | #FFA500 | |
| Coral | 255, 127, 80 | #FF7F50 | |
| Tomato | 255, 99, 71 | #FF6347 | |
| Gold | 255, 215, 0 | #FFD700 |
Technical Details
RGB color model uses 8 bits per channel (0-255), giving 24-bit color depth with 16,777,216 possible colors. Hex color codes represent these same values in base-16 notation, where each channel uses 2 hex digits (00-FF).
Hex colors are used in CSS (color: #FF5733), HTML attributes, SVG, and most web technologies. The shorthand notation uses 3 digits when each pair is identical (e.g., #AABBCC can be written as #ABC).
Frequently Asked Questions
How do I convert RGB to hex?
Convert each RGB value (0-255) to a two-digit hexadecimal number and combine them. For example, RGB(255, 87, 51) becomes FF (255), 57 (87), 33 (51) = #FF5733.
What RGB values make white and black?
White is RGB(255, 255, 255) which converts to #FFFFFF. Black is RGB(0, 0, 0) which converts to #000000. Gray is any value where R, G, and B are equal, like RGB(128, 128, 128) = #808080.
Why do web developers need RGB to hex conversion?
CSS and HTML primarily use hex color codes (#FF5733) rather than RGB notation. When picking colors in design tools that show RGB values, developers need to convert them to hex for use in stylesheets.
What is the range of RGB values?
Each RGB channel ranges from 0 to 255 (8 bits). Zero means no light from that channel, 255 means maximum intensity. This gives 256 x 256 x 256 = 16,777,216 possible colors.
Can I convert RGBA to hex?
Yes. RGBA adds an alpha (transparency) channel. The hex equivalent uses 8 digits (#RRGGBBAA). For example, RGBA(255, 87, 51, 0.5) becomes #FF573380 where 80 is 50% opacity in hex.
Solved Examples โ RGB to Hex Conversions
Example 1: Convert rgb(46, 204, 113) to Hex
Solution:
R: 46 รท 16 = 2 remainder 14 โ 2E
G: 204 รท 16 = 12 remainder 12 โ CC
B: 113 รท 16 = 7 remainder 1 โ 71
Answer: #2ECC71 (Emerald Green)
Example 2: Convert rgb(52, 152, 219) to Hex
Solution:
R: 52 รท 16 = 3 remainder 4 โ 34
G: 152 รท 16 = 9 remainder 8 โ 98
B: 219 รท 16 = 13 remainder 11 โ DB
Answer: #3498DB (Peter River Blue)
Example 3: Convert rgb(231, 76, 60) to Hex
Solution:
R: 231 รท 16 = 14 remainder 7 โ E7
G: 76 รท 16 = 4 remainder 12 โ 4C
B: 60 รท 16 = 3 remainder 12 โ 3C
Answer: #E74C3C (Alizarin Red)
Practice Questions
Convert these RGB values to hex codes:
- rgb(255, 165, 0) โ ? (Answer: #FFA500 โ Orange)
- rgb(128, 0, 128) โ ? (Answer: #800080 โ Purple)
- rgb(0, 128, 128) โ ? (Answer: #008080 โ Teal)
- rgb(245, 245, 220) โ ? (Answer: #F5F5DC โ Beige)
- rgb(70, 130, 180) โ ? (Answer: #4682B4 โ Steel Blue)
- What RGB value gives #FF1493? (Answer: rgb(255, 20, 147) โ Deep Pink)
Why Convert RGB to Hex?
CSS stylesheets predominantly use hex color codes because they are compact (6 characters vs 13+ for rgb()). When you pick a color in Photoshop, Figma, or a color picker tool, you often get RGB values that need converting to hex for use in HTML/CSS. Brand guidelines frequently specify colors in RGB (for print) that web developers must convert to hex (for screens). SVG files and icon fonts also use hex notation exclusively.
Common Mistakes in RGB to Hex Conversion
The most common error is forgetting to pad single-digit hex values with a leading zero. For example, rgb(5, 10, 15) should become #050A0F, not #5A15 or #5AF. Another mistake is confusing the order โ always use RRGGBB, not BBGGRR (which some systems like OpenCV use internally). When values exceed 255, clamp them to 255 before converting. And remember: hex letters A-F can be uppercase or lowercase in CSS โ both #ff5733 and #FF5733 are valid and identical.
Key Takeaways
- RGB to hex conversion: divide each channel value by 16, the quotient is the first hex digit, the remainder is the second.
- Always pad with leading zeros: rgb(5, 0, 10) โ #05000A, not #50A.
- Values 0-9 map directly; 10=A, 11=B, 12=C, 13=D, 14=E, 15=F.
- Hex is case-insensitive in CSS: #ff5733 = #FF5733.
- Both formats represent identical 24-bit color (16.7 million possible colors).
- For transparency, use rgba() in CSS or 8-digit hex (#RRGGBBAA).