To convert HEX to RGB, split the code into three pairs and convert each from hexadecimal to decimal: #0B7A45 → 0B = 11, 7A = 122, 45 = 69, which gives rgb(11, 122, 69). Each pair runs from 00 (0) to FF (255). An 8-digit HEX code adds a fourth pair for opacity.
How HEX colour codes work
Screens mix every colour from red, green and blue light. A HEX code writes the strength of each as a two-digit hexadecimal number. Hexadecimal counts from 0 to 9 and then A to F, so two digits cover 0 to 255: 00 is none of that colour and FF is full strength.
#0B7A450B= 11Red7A= 122Green45= 69Bluergb(11, 122, 69)HEX, RGB and HSL compared
| Format | Example | Good for |
|---|---|---|
| HEX | #0B7A45 | Design tools, brand guides, compact CSS |
| HEX with alpha | #0B7A4580 | A transparent version of a brand colour |
| RGB | rgb(11, 122, 69) | Code, canvas and image editing |
| RGB with alpha | rgb(11 122 69 / 0.5) | Overlays and shadows in CSS |
| HSL | hsl(151, 83%, 26%) | Making lighter, darker or less saturated versions |
How to convert HEX to RGB by hand
- Drop the # and split the code into pairs: 0B, 7A, 45.
- For each pair, multiply the first digit by 16 and add the second. Letters count as A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.
- 0B = 0 × 16 + 11 = 11. 7A = 7 × 16 + 10 = 122. 45 = 4 × 16 + 5 = 69.
- Write it as rgb(11, 122, 69).
To go the other way, divide each number by 16: the whole number is the first digit and the remainder is the second. 122 ÷ 16 = 7 remainder 10, so 7A.
Converting in code
// JavaScript: HEX → RGB
const hex = "0B7A45";
const [r, g, b] = [0, 2, 4].map((i) => parseInt(hex.slice(i, i + 2), 16)); // [11, 122, 69]
// RGB → HEX
"#" + [11, 122, 69].map((n) => n.toString(16).padStart(2, "0")).join("").toUpperCase(); // "#0B7A45"Common colour codes
| Colour | HEX | RGB |
|---|---|---|
| White | #FFFFFF | rgb(255, 255, 255) |
| Black | #000000 | rgb(0, 0, 0) |
| Red | #FF0000 | rgb(255, 0, 0) |
| Green | #00FF00 | rgb(0, 255, 0) |
| Blue | #0000FF | rgb(0, 0, 255) |
| Mid grey | #808080 | rgb(128, 128, 128) |
Need a full set of matching colours rather than one conversion? The Color Palette Generator builds harmonies and a 50–900 scale from any colour you enter here.