DevBolt
Processed in your browser. Your data never leaves your device.

RGB to HEX Converter

Convert RGB color values to HEX codes instantly. Enter red, green, and blue values (0–255) and get the corresponding HEX code with a live color preview.

← Back to tools

Color Converter

Convert colors between HEX, RGB, and HSL formats.

How RGB to HEX conversion works

Each RGB value (0–255) is converted to a two-digit hexadecimal number. Red 255 → FF, Green 87 → 57, Blue 51 → 33, combined as #FF5733. The formula converts each decimal channel to base-16 and pads single-digit results with a leading zero.

// 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}"
rgb_to_hex(255, 87, 51)  # "#ff5733"

/* CSS — both formats are equivalent */
color: rgb(255, 87, 51);
color: #ff5733;

Shorthand HEX codes

When each hex pair has identical digits (e.g., #AABBCC), the code can be shortened to #ABC. However, #FF5733 cannot be shortened because 57 and 33 have different digits. CSS supports both 3-digit and 6-digit HEX codes. Modern CSS also supports 8-digit hex for alpha transparency: #FF573380 is 50% transparent.

Frequently Asked Questions

How do I convert RGB 255, 0, 0 to HEX?

RGB(255, 0, 0) = #FF0000. Red: 255 → FF, Green: 0 → 00, Blue: 0 → 00. This is pure red.

What is the HEX code for white?

#FFFFFF — all channels at maximum (RGB 255, 255, 255). In shorthand: #FFF.

Related Convert Tools