Free tool · no sign-up

HEX to RGB Converter

Type or paste a colour in HEX, RGB or HSL and the other two update instantly. Adjust opacity, see a live preview and the contrast against white and black, and copy the CSS.

By Jamiul Alam Rejon · Updated

#0B7A45rgb(11, 122, 69)
Red
11 · 0B
Green
122 · 7A
Blue
69 · 45
Hue · Sat · Light
151° · 83% · 26%
Contrast on white
5.41:1
Contrast on black
3.88:1
Quick answer

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.

#0B7A45
0B= 11Red
7A= 122Green
45= 69Blue
rgb(11, 122, 69)
A HEX code is three pairs of base-16 digits: red, green and blue, each from 00 (0) to FF (255).

HEX, RGB and HSL compared

FormatExampleGood for
HEX#0B7A45Design tools, brand guides, compact CSS
HEX with alpha#0B7A4580A transparent version of a brand colour
RGBrgb(11, 122, 69)Code, canvas and image editing
RGB with alphargb(11 122 69 / 0.5)Overlays and shadows in CSS
HSLhsl(151, 83%, 26%)Making lighter, darker or less saturated versions

How to convert HEX to RGB by hand

  1. Drop the # and split the code into pairs: 0B, 7A, 45.
  2. 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.
  3. 0B = 0 × 16 + 11 = 11. 7A = 7 × 16 + 10 = 122. 45 = 4 × 16 + 5 = 69.
  4. 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

ColourHEXRGB
White#FFFFFFrgb(255, 255, 255)
Black#000000rgb(0, 0, 0)
Red#FF0000rgb(255, 0, 0)
Green#00FF00rgb(0, 255, 0)
Blue#0000FFrgb(0, 0, 255)
Mid grey#808080rgb(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.

Frequently asked questions

How do I convert HEX to RGB?

Split the six-digit code into three pairs and convert each from base 16 to base 10. #0B7A45 becomes 0B = 11, 7A = 122 and 45 = 69, so rgb(11, 122, 69).

How do I convert RGB to HEX?

Convert each of the three numbers (0–255) to a two-digit base-16 number and join them after a #. rgb(255, 87, 51) becomes FF, 57, 33: #FF5733.

What is a 3-digit HEX code?

A shorthand where each digit is doubled. #F60 is the same as #FF6600. It only works when both digits of every pair are the same.

What are 8-digit HEX codes?

The last two digits are the alpha (opacity) channel, from 00 (transparent) to FF (solid). #0B7A4580 is the same colour at about 50% opacity.

When should I use HSL instead of HEX?

HSL (hue, saturation, lightness) is easier to adjust by hand. To make a lighter or darker version of a colour, change only the lightness, which is how the colour palette generator builds its tints and shades.

Which format should I use in CSS?

All modern browsers support HEX, rgb() and hsl(), including alpha. HEX is the most compact; rgb() with a slash for alpha, like rgb(11 122 69 / 0.5), is the most readable when you need transparency.