HEX to RGB Converter

HEX to RGB Converter

Convert hex to RGB, RGBA and HSL in one go, or turn RGB values back into a hex colour code.

RGB to hex: type channel values from 0 to 255 and the hex code updates above.
Aa whiteAa black
RGB value
rgb(0, 0, 0)
HEX
RGB
RGBA
HSL
0 to 1
Percent
CSS var
0with white text
0with black text

Contrast uses the WCAG 2 relative luminance formula for sRGB and ignores opacity. Everything runs in your browser.

This free hex to RGB converter turns any hex colour code into the rgb(), rgba() and HSL values designers, developers and students paste into CSS, design apps and slides. It reads the 3, 4, 6 and 8 digit formats defined in the CSS hex colour specification, so shorthand and transparent colours work too. It also converts RGB to hex in reverse and checks whether white or black text on the colour is readable.

Quick answer: To convert hex to RGB, split the six digit code into three pairs and turn each pair from base 16 into base 10. For #2E86AB, 2E = 2 × 16 + 14 = 46, 86 = 134 and AB = 171, so the colour is rgb(46, 134, 171). A fourth pair, if present, sets opacity.

Hex to RGB converter turning #2E86AB into rgb(46, 134, 171) with RGBA, HSL and a contrast check
How the HEX to RGB Converter works: HEX colour code in, rgb(), rgba(), HSL and contrast out.

What Is a HEX to RGB Converter?

A HEX to RGB converter is a colour code converter that rewrites a hexadecimal colour such as #2E86AB as three decimal channel values for red, green and blue, each from 0 to 255. Both notations describe exactly the same sRGB colour, so nothing is lost either way. Hex is compact and common in style guides, while rgb() is easier to read, edit and combine with transparency.

The formula in plain words: each channel value equals the first hex digit times 16, plus the second hex digit, where the letters A to F stand for 10 to 15. Going from RGB to hex reverses this: divide by 16 for the first digit and use the remainder for the second.

How to Use the HEX to RGB Converter

Step 1: Enter a Hex Code

Type or paste a code with or without the # sign, or use the colour picker. Three and four digit shorthand is expanded for you, and an eight digit code reads its last pair as opacity.

Step 1: type a hex colour code or pick a colour

Step 2: Copy the Format You Need

The table lists seven ready values: hex, rgb(), rgba(), hsl(), 0 to 1 decimals for shaders and apps, percentages, and a space separated CSS custom property. Each row has its own Copy button.

Step 2: copy the RGB, RGBA, HSL or CSS variable value

Step 3: Check the Contrast

The swatch previews white and black text on your colour, and the two ratios show which one is readable. The tool tells you which text colour to use and whether it passes the AA level.

Step 3: check white and black text contrast against WCAG

Step 4: Convert RGB to Hex

To go the other way, type red, green and blue values from 0 to 255 and an opacity percentage. The hex field updates at once, adding an alpha pair only when opacity is below 100%.

Step 4: type red, green, blue and opacity to convert RGB to hex

How Do You Convert Hex to RGB by Hand?

You convert hex to RGB by hand by reading the code as three two digit base 16 numbers. Remove the #, split #FFA07A into FF, A0 and 7A, then multiply each first digit by 16 and add the second. FF = 15 × 16 + 15 = 255, A0 = 10 × 16 + 0 = 160 and 7A = 7 × 16 + 10 = 122, giving rgb(255, 160, 122), a light salmon.

Base 16 works like the binary and decimal systems you may already know, just with sixteen symbols per place. If number bases are new to you, the binary to decimal converter shows the same place value idea with only two symbols, which makes the pattern easy to see.

How Do You Convert RGB to Hex?

To convert RGB to hex, divide each channel by 16: the whole number result is the first digit and the remainder is the second. For rgb(46, 134, 171), 46 ÷ 16 = 2 remainder 14 (E), 134 ÷ 16 = 8 remainder 6, and 171 ÷ 16 = 10 (A) remainder 11 (B), so the code is #2E86AB. Values below 16 need a leading zero, so 9 becomes 09.

Common Colours: Hex to RGB Table

Colour (CSS name)HexRGB
Orange#FFA500255, 165, 0
Gold#FFD700255, 215, 0
Teal#0080800, 128, 128
Navy#0000800, 0, 128
Slate grey#708090112, 128, 144
Crimson#DC143C220, 20, 60
Rebecca purple#663399102, 51, 153

What Do 3, 4 and 8 Digit Hex Codes Mean?

A 3 digit code is shorthand where every digit is doubled, so #3C9 means #33CC99, or rgb(51, 204, 153). An 8 digit code adds a fourth pair for alpha, where 00 is fully transparent and FF is solid. A 4 digit code is the shorthand version of that. Opacity converts as the pair value divided by 255, so 80 means 128 ÷ 255 = 0.502, roughly 50%.

Worked example: Priya, a web designer, has the brand colour #2E86AB and needs an overlay at 80% opacity. The hex to RGB step gives 46, 134, 171. For the alpha pair, 0.8 × 255 = 204, which is CC in hex. Her CSS can use either #2E86ABCC or rgba(46, 134, 171, 0.8), and both render the same.

Will Text on This Colour Be Readable?

Text is readable for most people when its contrast ratio with the background is at least 4.5 : 1, the AA level for normal text in the Web Content Accessibility Guidelines, or 3 : 1 for large text. The ratio comes from the relative luminance of the two colours. For #2E86AB, white text scores about 4.1 : 1 and black about 5.1 : 1, so black is the safer choice.

If you embed small images in CSS alongside your colours, the image to Base64 encoder creates data URIs that sit next to the rgb() values in the same stylesheet. Formulas and contrast levels checked October 2026.

Key HEX and RGB Colour Terms Explained

These terms cover the colour maths behind every hex to RGB conversion on this page, from base 16 pairs to opacity and contrast ratios.

Hexadecimal
A base 16 number system using the digits 0 to 9 and the letters A to F for ten to fifteen. Two hex digits store any value from 0 to 255, which is why colour codes use pairs.
RGB colour model
A way of describing colour by mixing red, green and blue light. On the web each channel runs from 0 to 255, so rgb(46, 134, 171) means a little red, more green and most blue.
Alpha channel
The value that controls opacity. In an eight digit hex code it is the last pair, from 00 for fully transparent to FF for solid, and in rgba() it is written as a decimal from 0 to 1.
HSL
Hue, saturation and lightness, an alternative to RGB that describes colour as an angle on the colour wheel plus two percentages. It is handy for making lighter or darker shades of one brand colour.
Contrast ratio
A number from 1 : 1 to 21 : 1 comparing the relative luminance of text and background colours. WCAG AA asks for at least 4.5 : 1 for normal text and 3 : 1 for large text.
</>Embed this calculator on your website

Add the free HEX to RGB Converter to your own site or blog. Copy the code below and paste it into an HTML block. It resizes itself and works on phones.

How we checked this tool: Zahid Awais built this tool, checked it against the official rules or published standards where they apply, and tested it against worked examples. Results are estimates for planning, not personal financial or tax advice. Read our editorial policy and disclaimer, or report an error.

Frequently Asked Questions

What is #FFFFFF in RGB?

#FFFFFF is rgb(255, 255, 255), which is pure white. Each FF pair equals 15 × 16 + 15 = 255, the maximum value for a channel, so red, green and blue are all at full strength.

Is hex or RGB better for CSS?

Neither is better, because both describe the same sRGB colour and every modern browser supports them. Hex is shorter for solid colours, while rgb() is easier to read and adjust, especially when you add transparency.

How do I convert a 3 digit hex code to RGB?

Double each digit first, then convert as normal. For example, #F80 becomes #FF8800, which is rgb(255, 136, 0). The shorthand only works for colours where both digits of every pair are the same.

What does the alpha value in an 8 digit hex code mean?

The last pair sets opacity from 00 (fully transparent) to FF (fully solid). Divide its decimal value by 255 to get the rgba() alpha, so CC equals 204 ÷ 255 = 0.8, or 80% opacity.

Why does my converted colour look different in another app?

The numbers are identical, but some apps and screens use wider colour spaces such as Display P3, or apply colour profiles to images. Make sure both apps treat the value as sRGB for a matching result.

Is hex to RGB conversion lossless?

Yes. Every two digit hex pair maps to exactly one whole number from 0 to 255, so converting hex to RGB and back always returns the original code, apart from upper or lower case letters.