RGB to HEX Color Converter
Convert RGB color values to HEX codes. Enter R, G, B values and get the HEX equivalent instantly.
Open Color Converter →How RGB to HEX Conversion Works
RGB to HEX conversion transforms each channel value (0-255) into a two-character hexadecimal string. The formula: convert each decimal value to hex and pad to two digits. For example, R:255 → FF, G:87 → 57, B:51 → 33, producing
#FF5733. Values below 16 need a leading zero: G:10 → 0A. In JavaScript, value.toString(16).padStart(2, '0') handles this conversion.Tips for Working with RGB Values
- Range: Each channel is 0-255 (8 bits). 0 is no color, 255 is full intensity.
- Common colors: Black is (0,0,0), white is (255,255,255), red is (255,0,0).
- Color math: Averaging two colors:
((r1+r2)/2, (g1+g2)/2, (b1+b2)/2). Lightening: increase all channels. Darkening: decrease all channels. - Opacity: Add a 4th value (alpha) for transparency:
rgba(255, 87, 51, 0.5)is 50% transparent.
// JavaScript - RGB to HEX
function rgbToHex(r, g, b) {
return '#' + [r, g, b]
.map(v => v.toString(16).padStart(2, '0'))
.join('');
}
rgbToHex(255, 87, 51); // "#ff5733"
// Python
def rgb_to_hex(r, g, b):
return f'#{r:02x}{g:02x}{b:02x}'
// CSS equivalents
color: rgb(255, 87, 51);
color: #ff5733;