Color · Converter
RGB to hex converter.
Type red, green and blue (0 to 255) and get the hex code. Add an alpha value to get an 8 digit hex. Edit the hex side and the RGB updates too.
Convert both ways
All formats
Enter a color to see every format.
How RGB to HEX works
The steps
- Check the range. Each of red, green and blue is a whole number from 0 to 255. Percentages such as rgb(100%, 0%, 50%) are scaled by 255 and rounded.
- Convert each to base 16. Divide by 16: the quotient is the first digit and the remainder is the second. 87 ÷ 16 = 5 remainder 7, so 87 is 57. 255 is FF and 51 is 33.
- Pad to two digits. 5 becomes 05, so rgb(1, 2, 3) is #010203.
- Join them behind a #. 255, 87, 51 gives
#FF5733. - Alpha. If you give an alpha from 0 to 1, multiply by 255, round, and write it as a fourth pair: 0.5 × 255 = 127.5, rounded to 128, is 80, so you get
#FF573380. An alpha of 1 adds nothing.
Sources
- CSS Color Module Level 4, W3C Candidate Recommendation Draft (retrieved October 16, 2026).
Cite this page: TNAADO Tools, “RGB to Hex Converter,” tools.tnaado.ca/color/rgb-to-hex/, formulas from the W3C CSS Color specifications, retrieved October 16, 2026.
20 common colors
Click Use to load a row into the converter. The names are CSS color names; CMYK is the simple screen formula described above.
| Color | HEX | RGB | HSL | CMYK | Load |
|---|---|---|---|---|---|
| black | #000000 | rgb(0, 0, 0) | hsl(0, 0%, 0%) | cmyk(0%, 0%, 0%, 100%) | |
| white | #FFFFFF | rgb(255, 255, 255) | hsl(0, 0%, 100%) | cmyk(0%, 0%, 0%, 0%) | |
| red | #FF0000 | rgb(255, 0, 0) | hsl(0, 100%, 50%) | cmyk(0%, 100%, 100%, 0%) | |
| lime | #00FF00 | rgb(0, 255, 0) | hsl(120, 100%, 50%) | cmyk(100%, 0%, 100%, 0%) | |
| blue | #0000FF | rgb(0, 0, 255) | hsl(240, 100%, 50%) | cmyk(100%, 100%, 0%, 0%) | |
| yellow | #FFFF00 | rgb(255, 255, 0) | hsl(60, 100%, 50%) | cmyk(0%, 0%, 100%, 0%) | |
| cyan | #00FFFF | rgb(0, 255, 255) | hsl(180, 100%, 50%) | cmyk(100%, 0%, 0%, 0%) | |
| magenta | #FF00FF | rgb(255, 0, 255) | hsl(300, 100%, 50%) | cmyk(0%, 100%, 0%, 0%) | |
| gray | #808080 | rgb(128, 128, 128) | hsl(0, 0%, 50%) | cmyk(0%, 0%, 0%, 50%) | |
| silver | #C0C0C0 | rgb(192, 192, 192) | hsl(0, 0%, 75%) | cmyk(0%, 0%, 0%, 25%) | |
| maroon | #800000 | rgb(128, 0, 0) | hsl(0, 100%, 25%) | cmyk(0%, 100%, 100%, 50%) | |
| olive | #808000 | rgb(128, 128, 0) | hsl(60, 100%, 25%) | cmyk(0%, 0%, 100%, 50%) | |
| green | #008000 | rgb(0, 128, 0) | hsl(120, 100%, 25%) | cmyk(100%, 0%, 100%, 50%) | |
| purple | #800080 | rgb(128, 0, 128) | hsl(300, 100%, 25%) | cmyk(0%, 100%, 0%, 50%) | |
| teal | #008080 | rgb(0, 128, 128) | hsl(180, 100%, 25%) | cmyk(100%, 0%, 0%, 50%) | |
| navy | #000080 | rgb(0, 0, 128) | hsl(240, 100%, 25%) | cmyk(100%, 100%, 0%, 50%) | |
| orange | #FFA500 | rgb(255, 165, 0) | hsl(39, 100%, 50%) | cmyk(0%, 35%, 100%, 0%) | |
| pink | #FFC0CB | rgb(255, 192, 203) | hsl(350, 100%, 88%) | cmyk(0%, 25%, 20%, 0%) | |
| brown | #A52A2A | rgb(165, 42, 42) | hsl(0, 59%, 41%) | cmyk(0%, 75%, 75%, 35%) | |
| gold | #FFD700 | rgb(255, 215, 0) | hsl(51, 100%, 50%) | cmyk(0%, 16%, 100%, 0%) |
RGB to Hex FAQ
How do I convert RGB to hex?
Write each of red, green and blue in base 16 with two digits and join them after a #. rgb(255, 87, 51) is FF, 57, 33, so #FF5733. Type the three values above and the tool does it for you.
Can I convert rgba() with transparency?
Yes. Enter rgba(255, 87, 51, 0.5) and you get the 8 digit hex #FF573380. The alpha is multiplied by 255 and rounded to the nearest whole number before it is written in hex.
Does it accept values without rgb()?
Yes. 255 87 51 and 255, 87, 51 both work. The modern space-separated form with a slash, rgb(255 87 51 / 50%), is accepted too.
What happens with a value above 255 or below 0?
The tool tells you the value is out of range instead of silently clamping it. Each channel must be between 0 and 255.
Can I shorten the hex code?
When both digits of every pair match, the code can be written with 3 digits, and the tool shows that shorthand under the result. For example #FFAA00 is #FA0.
Is anything I type sent to a server?
No. The conversion runs in your browser and nothing is uploaded or stored.
What this does, and what it does not
This converts between written forms of sRGB colors, the color space browsers use for CSS by default. It does not convert to other color spaces such as Display P3 or Lab. Everything runs in your browser; nothing you type is sent anywhere.