Hex → RGB
Paste a hex color, get RGB instantly. #2563eb →
rgb(37, 99, 235). The full converter at the bottom
also gives you HSL and OKLCH.
The conversion in one paragraph
Hex colors pack three 8-bit RGB channels into a 6-character hexadecimal string. Each pair of hex digits represents one byte (0–255):
#2563eb
│└┴ blue: 0xeb = 235
│└── green: 0x63 = 99
└─── red: 0x25 = 37
rgb(37, 99, 235) The 3-digit shorthand
CSS allows a 3-digit form where each digit is doubled:
#27e → #2277ee → rgb(34, 119, 238)
#fff → #ffffff → rgb(255, 255, 255)
#000 → #000000 → rgb(0, 0, 0) Useful when the value happens to repeat each digit; otherwise stick with the full 6-digit form.
Common conversions
| Hex | RGB | Name |
|---|---|---|
#000000 | rgb(0, 0, 0) | Black |
#ffffff | rgb(255, 255, 255) | White |
#ff0000 | rgb(255, 0, 0) | Red |
#00ff00 | rgb(0, 255, 0) | Green (lime in CSS) |
#0000ff | rgb(0, 0, 255) | Blue |
#2563eb | rgb(37, 99, 235) | Tailwind blue-600 |
#7c3aed | rgb(124, 58, 237) | Tailwind violet-600 |
#10b981 | rgb(16, 185, 129) | Tailwind emerald-500 |
#f59e0b | rgb(245, 158, 11) | Tailwind amber-500 |
#ef4444 | rgb(239, 68, 68) | Tailwind red-500 |
In code
// JavaScript / Node — most concise
const rgb = (h) => h.match(/[0-9a-f]{2}/gi).map(c => parseInt(c, 16));
rgb("2563eb"); // [37, 99, 235]
// JavaScript — with shorthand support
function hexToRgb(hex) {
let h = hex.replace(/^#|^0x/i, "");
if (h.length === 3) h = h.split("").map(c => c + c).join("");
if (h.length !== 6) throw new Error("Invalid hex");
return [
parseInt(h.slice(0,2), 16),
parseInt(h.slice(2,4), 16),
parseInt(h.slice(4,6), 16),
];
}
// Python
def hex_to_rgb(s):
s = s.lstrip("#")
if len(s) == 3:
s = "".join(c + c for c in s)
return tuple(int(s[i:i+2], 16) for i in (0, 2, 4))
// Bash
hex="2563eb"
printf "%d, %d, %d\n" 0x${hex:0:2} 0x${hex:2:2} 0x${hex:4:2}
// Go
import "strconv"
r, _ := strconv.ParseInt(hex[:2], 16, 32) Common pitfalls
- Stripping
#: handle inputs both with and without the leading hash. - Case sensitivity:
#2563EB=#2563eb. Normalize to one case for comparisons. - 4-digit and 8-digit hex: CSS Color Module 4 added
#RGBAand#RRGGBBAAfor alpha. The 4-digit form expands like the 3-digit one. - Don't roundtrip blindly. Hex → RGB → hex always works for sRGB, but hex → HSL → hex involves rounding and may not roundtrip.
Try the reverse direction
- RGB → Hex — paste RGB, get hex
- Full converter — also includes HSL and OKLCH
- Contrast checker — check accessibility
FAQ
What's the formula?
Each pair of hex digits is one byte (0–255). #RRGGBB → rgb(R, G, B) where each component is parsed from 2 hex digits. #fff is shorthand for #ffffff — repeat each digit.
Does it handle the 3-digit shorthand?
Yes. #27e expands to #2277ee = rgb(34, 119, 238). The expansion is per-channel: each single hex digit is doubled.
Can I paste with or without #?
Both. 2563eb, #2563eb, and 0x2563eb all work — the parser strips common prefixes.