HEX ↔ RGB Color Converter

Convert HEX color codes to RGB and back instantly. Live preview, HSL values, and copy-ready CSS snippets included.

Pick a color to populate both converters

Click to open the system color picker

Type a HEX code above to see the conversion.

Common web colors

Click any color to populate the converter.

Red#FF0000rgb(255,0,0)
Green#008000rgb(0,128,0)
Blue#0000FFrgb(0,0,255)
Yellow#FFFF00rgb(255,255,0)
Cyan#00FFFFrgb(0,255,255)
Magenta#FF00FFrgb(255,0,255)
Orange#FFA500rgb(255,165,0)
Purple#800080rgb(128,0,128)
White#FFFFFFrgb(255,255,255)
Black#000000rgb(0,0,0)
Gray#808080rgb(128,128,128)
Navy#000080rgb(0,0,128)

What is a HEX color code?

A HEX color code is a six-digit hexadecimal number prefixed with # that encodes a color in the RGB color model. The format is #RRGGBB, where RR, GG, and BB are two-digit hex values for red, green, and blue respectively. Each pair ranges from 00 (decimal 0, no intensity) to FF (decimal 255, full intensity).

For example, #FF5733 breaks down as R=255, G=87, B=51 — a vivid orange-red. Pure red is #FF0000, pure white is #FFFFFF, and pure black is #000000. HEX codes are case-insensitive, so #ff5733 and #FF5733 are identical. A shorthand 3-digit form is also valid: #F53 expands to #FF5533.

HEX to RGB formula

The conversion is straightforward base-16 to base-10 arithmetic. Given a 6-character hex string:

hex = "FF5733" R = parseInt(hex[0:2], 16) → parseInt("FF", 16) = 255 G = parseInt(hex[2:4], 16) → parseInt("57", 16) = 87 B = parseInt(hex[4:6], 16) → parseInt("33", 16) = 51 Result: rgb(255, 87, 51)

How to convert HEX to RGB in Python

Use the built-in int() function with base 16, or let Pillow do the heavy lifting:

# Method 1: manual parsing hex_code = "FF5733" r = int(hex_code[0:2], 16) # 255 g = int(hex_code[2:4], 16) # 87 b = int(hex_code[4:6], 16) # 51 print(f"rgb({r}, {g}, {b})") # rgb(255, 87, 51) # Method 2: Pillow (PIL) — handles #RRGGBB and named colors from PIL import ImageColor rgb = ImageColor.getrgb("#FF5733") print(rgb) # (255, 87, 51) rgb2 = ImageColor.getrgb("red") print(rgb2) # (255, 0, 0) # Method 3: struct / bytes (compact) hex_bytes = bytes.fromhex("FF5733") r, g, b = hex_bytes print(r, g, b) # 255 87 51 # Reverse: RGB → HEX def rgb_to_hex(r, g, b): return f"#{r:02X}{g:02X}{b:02X}" print(rgb_to_hex(255, 87, 51)) # #FF5733

How to convert HEX to RGB in JavaScript

// HEX → RGB function hexToRgb(hex) { const clean = hex.replace(/^#/, ''); const r = parseInt(clean.slice(0, 2), 16); const g = parseInt(clean.slice(2, 4), 16); const b = parseInt(clean.slice(4, 6), 16); return { r, g, b }; } console.log(hexToRgb('#FF5733')); // { r: 255, g: 87, b: 51 } // RGB → HEX function rgbToHex(r, g, b) { const toHex = (n) => n.toString(16).padStart(2, '0').toUpperCase(); return `#${toHex(r)}${toHex(g)}${toHex(b)}`; } console.log(rgbToHex(255, 87, 51)); // '#FF5733' // CSS usage const { r, g, b } = hexToRgb('#FF5733'); element.style.backgroundColor = `rgb(${r}, ${g}, ${b})`;

Frequently asked questions

What is a HEX color code?

A HEX color code is a six-digit hexadecimal number (prefixed with #) that represents a color as three two-digit values for red, green, and blue. Each pair ranges from 00 (0) to FF (255). For example, #FF0000 is pure red.

How do I convert HEX to RGB?

Split the HEX string into three pairs and convert each from base-16 to base-10. In Python: int("FF", 16) = 255. In JavaScript: parseInt("FF", 16) = 255. This tool does it instantly as you type.

What is RGB?

RGB stands for Red, Green, Blue — the three primary colors of light. In digital color, each channel ranges from 0 to 255. Mixing all three at 255 gives white; all at 0 gives black. Screens use RGB to display every color you see.

What is HSL?

HSL stands for Hue, Saturation, Lightness. Hue is the color angle on a 0–360° wheel, saturation is the color intensity (0–100%), and lightness controls how light or dark it is (0–100%). HSL is often easier for designers to reason about than RGB or HEX.