How Do I Convert Hex to RGB?
#3498db = rgb(52, 152, 219). To convert: split the hex code into three pairs (34, 98, db), then convert each pair from hexadecimal to decimal. 34 hex = 3×16 + 4 = 52. 98 hex = 9×16 + 8 = 152. db hex = 13×16 + 11 = 219.
Step-by-Step Conversion
- Remove the
#prefix:3498db - Split into three pairs:
34,98,db - Convert each pair from hex (base 16) to decimal (base 10):
- Red:
34→ 3×16 + 4 = 52 - Green:
98→ 9×16 + 8 = 152 - Blue:
db→ 13×16 + 11 = 219
- Red:
- Result:
rgb(52, 152, 219)
Common Conversions
| Hex | RGB | Color |
|---|---|---|
#FF0000 |
rgb(255, 0, 0) | Red |
#00FF00 |
rgb(0, 255, 0) | Green |
#0000FF |
rgb(0, 0, 255) | Blue |
#3498db |
rgb(52, 152, 219) | Dodger Blue |
Shorthand Hex Codes
A 3-character hex code like #39d is shorthand for #3399dd. Each character is doubled: 3 becomes 33, 9 becomes 99, d becomes dd. This gives rgb(51, 153, 221).
In Code
// JavaScript
function hexToRgb(hex) {
const r = parseInt(hex.slice(1, 3), 16);
const g = parseInt(hex.slice(3, 5), 16);
const b = parseInt(hex.slice(5, 7), 16);
return { r, g, b };
}
hexToRgb('#3498db'); // { r: 52, g: 152, b: 219 }
Use the gen8x hex-to-RGB converter for instant conversions with HSL output and color preview.