Enter a RGB color below to get the exact HEX value instantly, plus every other format, right in your browser.
When you need RGB to HEX
Colors often arrive as rgb() strings or integer triples. The getComputedStyle call returns colors in rgb() form, Canvas getImageData yields plain numbers, and image libraries print tuples. When you need to store that color in a design token file, a Tailwind config, an SVG fill or an HTML email, one HEX string is shorter and easier to compare in a diff. Enter the three channels here to get the six-digit code, then see whether it can be shortened to three digits.
Typical uses
- Turning getComputedStyle output such as rgb(34, 139, 34) back into a HEX value for a design token file.
- Labeling a palette swatch with a HEX string after reading its pixel through Canvas getImageData.
- Putting a tuple printed by Pillow or OpenCV into an SVG fill attribute or an HTML email template.
How to convert RGB to HEX
A HEX color code is the same RGB color written in hexadecimal (base-16). The six characters after the # sign form three pairs (RR, GG and BB), one pair per channel.
To convert HEX to RGB, translate each pair from base-16 to decimal: FF equals 255, 57 equals 87, 33 equals 51. To convert RGB to HEX, write each channel value (0-255) as a two-digit hexadecimal number.
Worked example
- R: 30 ÷ 16 = 1, remainder 14 → 1E
- G: 144 ÷ 16 = 9, remainder 0 → 90
- B: 255 ÷ 16 = 15, remainder 15 → FF
rgb(30, 144, 255) = #1E90FF
Tip: If your numbers come from OpenCV, remember that it stores channels in B, G, R order by default. Reorder them to R, G, B before entering them here, otherwise the HEX will show red and blue swapped and the color will look wrong.
Common colors: RGB to HEX
| Color | RGB | HEX |
|---|---|---|
| Red | rgb(255, 0, 0) | #FF0000 |
| Orange | rgb(255, 165, 0) | #FFA500 |
| Yellow | rgb(255, 255, 0) | #FFFF00 |
| Lime | rgb(0, 255, 0) | #00FF00 |
| Green | rgb(0, 128, 0) | #008000 |
| Cyan | rgb(0, 255, 255) | #00FFFF |
| Teal | rgb(0, 128, 128) | #008080 |
| Blue | rgb(0, 0, 255) | #0000FF |
| Navy | rgb(0, 0, 128) | #000080 |
| Purple | rgb(128, 0, 128) | #800080 |
| Magenta | rgb(255, 0, 255) | #FF00FF |
| Pink | rgb(255, 192, 203) | #FFC0CB |
| Brown | rgb(165, 42, 42) | #A52A2A |
| Gray | rgb(128, 128, 128) | #808080 |
| Black | rgb(0, 0, 0) | #000000 |
| White | rgb(255, 255, 255) | #FFFFFF |
Frequently asked questions
Which case should I use for the letters in the result?
Either works in CSS, SVG and HTML, because a browser treats #FF5733 and #ff5733 as the same color. Pick one style for the project and enforce it with a linter or formatter so diffs and code searches stay consistent.
Can the HEX result be shortened to three digits?
Only when each pair consists of two identical digits. For example rgb(255, 136, 0) gives #ff8800, which shortens to #f80. A channel such as 87 is 57 in hex, so it has no short form. Shorthand is optional and the six-digit form is always valid.
Are HEX and RGB the same color model?
Yes, a HEX code is just a compact notation for the same red, green and blue channels. #FF5733 and rgb(255, 87, 51) describe exactly the same color, so the conversion is lossless in both directions.
What do the six characters in a HEX code mean?
They are three two-digit hexadecimal numbers: the first pair is red, the second green, the third blue. Each pair ranges from 00 (0) to FF (255). Three-digit shorthand like #F53 expands by doubling each digit (#FF5533).
Does HEX support transparency?
Yes, an eight-digit code #RRGGBBAA adds an alpha pair, where 00 is fully transparent and FF is fully opaque. In CSS you can also use the rgba() notation, e.g. rgba(255, 87, 51, 0.5).
More color converters
Need to grab a color from an image or screenshot? Try the free Pixel Color Picker →