How this conversion is calculated
- Divide each channel by 16. The whole part is the first hex digit, the remainder the second.
- Red 99 = 6 x 16 + 3, so 63. Green 102 = 6 x 16 + 6, so 66. Blue 241 = 15 x 16 + 1, so F1.
- Join them after a #: #6366F1.
Code snippets
color: #6366F1;--brand: #6366F1;$brand: #6366F1;UIColor(red: 0.388, green: 0.4, blue: 0.945, alpha: 1)Color(red: 0.388, green: 0.4, blue: 0.945, opacity: 1)<color name="brand">#6366F1</color>Color(0xFF6366F1)Color.argb(255, 99, 102, 241)Color(0xFF6366F1)new Color32(99, 102, 241, 255)Color.FromArgb(255, 99, 102, 241)(99, 102, 241)Convert a list
Paste up to 1,000 values, one per line. Each line is converted to HEX.
More color formats (HWB, LAB, LCH, OKLab, XYZ and more)
Common colors reference table
Click a name to load it into the converter.
| Color | HEX | RGB | HSL |
|---|---|---|---|
| #000000 | rgb(0, 0, 0) | hsl(0, 0%, 0%) | |
| #FFFFFF | rgb(255, 255, 255) | hsl(0, 0%, 100%) | |
| #FF0000 | rgb(255, 0, 0) | hsl(0, 100%, 50%) | |
| #00FF00 | rgb(0, 255, 0) | hsl(120, 100%, 50%) | |
| #0000FF | rgb(0, 0, 255) | hsl(240, 100%, 50%) | |
| #FFFF00 | rgb(255, 255, 0) | hsl(60, 100%, 50%) | |
| #00FFFF | rgb(0, 255, 255) | hsl(180, 100%, 50%) | |
| #FF00FF | rgb(255, 0, 255) | hsl(300, 100%, 50%) | |
| #C0C0C0 | rgb(192, 192, 192) | hsl(0, 0%, 75%) | |
| #808080 | rgb(128, 128, 128) | hsl(0, 0%, 50%) | |
| #800000 | rgb(128, 0, 0) | hsl(0, 100%, 25%) | |
| #808000 | rgb(128, 128, 0) | hsl(60, 100%, 25%) | |
| #008000 | rgb(0, 128, 0) | hsl(120, 100%, 25%) | |
| #800080 | rgb(128, 0, 128) | hsl(300, 100%, 25%) | |
| #008080 | rgb(0, 128, 128) | hsl(180, 100%, 25%) | |
| #000080 | rgb(0, 0, 128) | hsl(240, 100%, 25%) | |
| #FFA500 | rgb(255, 165, 0) | hsl(39, 100%, 50%) | |
| #FF6347 | rgb(255, 99, 71) | hsl(9, 100%, 64%) | |
| #FFD700 | rgb(255, 215, 0) | hsl(51, 100%, 50%) | |
| #4B0082 | rgb(75, 0, 130) | hsl(275, 100%, 25%) |
How to use
Enter the RGB values
Type or paste into Input (RGB), for example rgb(24, 119, 242) or 24, 119, 242. You can also drag the Red, Green and Blue sliders or type into the number boxes beside them.
Check the preview and result
The swatch shows the color and the Result (HEX) card shows the code. If a value is out of range, a message explains the problem, such as a number above 255.
Copy the hex code
Press Copy on the result, or on the Lowercase variant if your codebase uses lowercase hex. For rgba() input, HEX without alpha gives the plain 6 digit code as well.
Why RGB to HEX Converter
- R, G and B sliders and number fields.
- Accepts rgb(), rgba(), modern syntax and bare numbers.
- rgba() input returns an 8 digit hex with alpha.
- Bulk list mode, worked math and code snippets.
RGB to hex: the manual method
Converting by hand takes three short divisions. Work through red, green and blue in turn. Divide the number by 16. The whole part becomes the first hex digit and the remainder the second. Use A for 10, B for 11, C for 12, D for 13, E for 14 and F for 15.
Example with rgb(24, 119, 242). Red: 24 / 16 = 1 remainder 8, giving 18. Green: 119 / 16 = 7 remainder 7, giving 77. Blue: 242 / 16 = 15 remainder 2, giving F2. Join them after a hash and you get #1877F2.
| RGB | HEX | Color |
|---|---|---|
| rgb(0, 0, 0) | #000000 | Black |
| rgb(255, 255, 255) | #FFFFFF | White |
| rgb(255, 0, 0) | #FF0000 | Red |
| rgb(0, 128, 0) | #008000 | Green |
| rgb(0, 0, 255) | #0000FF | Blue |
| rgb(128, 128, 128) | #808080 | Gray |
| rgb(255, 165, 0) | #FFA500 | Orange |
| rgb(24, 119, 242) | #1877F2 | A bright blue |