Lelifi·tools

Hex to RGB Converter

#3B82F6 splits into 59, 130, 246, because 3B is 59, 82 is 130 and F6 is 246. Each pair is a base 16 number, so F6 = 15 x 16 + 6 = 246. The 3 digit form #38F expands to #3388FF, which is 51, 136, 255.

Paste a hex color code to get its red, green and blue values, the alpha percentage, the rgb() and hsl() strings, and the contrast ratio against white and black.

By the Lelifi editors ·

Key takeaways

Hex to RGB for #3B82F6#3B82F6 splits into 3B, 82, F63B = 3 x 16 + 11 = 5982 = 8 x 16 + 2 = 130F6 = 15 x 16 + 6 = 246= rgb(59, 130, 246)
#3B82F6 converts pair by pair to rgb(59, 130, 246).
Channel strength in #3B82F6 (0 to 255 each)59130246Red 59 (59)Green 130 (130)Blue 246 (246)
The blue channel at 246 is close to the 255 ceiling, while red at 59 is low.
On this page
  1. Six hex digits are three pairs
  2. Worked example: #3B82F6
  3. The sixteen values each digit can hold
  4. Three digit shorthand
  5. Eight digit hex and transparency
  6. Common colors in both notations
  7. Reading hex in CSS and design tools
  8. Mistakes that produce the wrong color

Six hex digits are three pairs

A hex color code is a shorthand for three numbers. The six characters after the hash split into three pairs, and each pair is the red, green or blue value of the color, in that order. #3B82F6 is 3B for red, 82 for green and F6 for blue.

#RRGGBB
# 3B . 82 . F6

Each pair is a two digit number written in base 16, where the digits run 0 to 9 and then A to F for 10 to 15. The first character of the pair is worth 16 times its value, and the second is worth its value once, so the pair converts to a number from 0 to 255.

value = first digit x 16 + second digit

That gives 256 possible values per channel, which is why an 8 bit color channel runs from 0 to 255. Three channels of 256 values each is 256 x 256 x 256 = 16,777,216 possible colors in the standard RGB space.

Worked example: #3B82F6

Take the blue #3B82F6, one of the most common interface colors. Convert each pair on its own.

The color is rgb(59, 130, 246). Note that B is 11 and F is 15, because the letters continue the digit sequence after 9. A pair like 3B is not 3 and B side by side, it is 3 x 16 + 11.

The same color in HSL is hsl(217, 91%, 60%), which describes the hue in degrees, the saturation as a percentage and the lightness as a percentage. The RGB form is what the screen uses. The HSL form is often easier to adjust by hand, since raising the lightness number lightens the color without touching the hue.

Contrast against white for this color is 3.68 to 1, and against black it is 5.71 to 1. Both numbers come from the same channel values through a luminance formula, and both matter when the color is used for text.

The sixteen values each digit can hold

Hex digits are worth 0 to 15, and the letters cover the top end. This table is the whole alphabet of the notation.

DigitValueDigitValue
0088
1199
22A10
33B11
44C12
55D13
66E14
77F15

Common pairs come up often enough to memorize a few: 00 is 0, 33 is 51, 66 is 102, 80 is 128, 99 is 153, CC is 204 and FF is 255. The pair 80 is worth knowing because it is the halfway point at 128, and it is the pair most often used for 50% transparency.

Reading a pair gets faster with practice. The pattern is always the same: first digit times 16, plus the second digit. C8 is 12 x 16 + 8 = 200, and 4D is 4 x 16 + 13 = 77.

Three digit shorthand

When each pair repeats the same character, the code can be written with three digits. #FF8800 shortens to #F80, and #3388FF shortens to #38F. The rule is that each single digit doubles: F becomes FF, 8 becomes 88, 0 becomes 00.

The shorthand only works when both digits of a pair match. #3B8F cannot be shortened, because 3B and 8F have no repeated pair. A code like #ABC is valid and expands to #AABBCC, which is rgb(170, 187, 204).

Browsers have accepted the three digit form for decades, and the CSS Color Module Level 4 in the W3C specification keeps it alongside the six and eight digit forms. A four digit form also exists, #RGBA, which is the shorthand of the eight digit code.

Eight digit hex and transparency

The eight digit form adds an alpha pair at the end. #3B82F680 is the same blue as #3B82F6 with an alpha of 80, which is 128 out of 255, or about 50% opacity.

#RRGGBBAA
# 3B . 82 . F6 . 80

Alpha pairDecimalOpacity
0000%
335120%
6610240%
8012850%
9915360%
B317970%
CC20480%
E623090%
FF255100%

Alpha is not a color channel in the same sense as red, green and blue. It controls how much of what sits behind the color shows through, so the same alpha over a white background and over a black background produces two different visible colors. That is why an rgba value copied from one design can look wrong on another background.

Common colors in both notations

These are the codes that turn up most often in design work, converted to the rgb() form. The three digit shorthand is shown where one exists.

HexShorthandRGBColor
#000000#0000, 0, 0Black
#FFFFFF#FFF255, 255, 255White
#FF0000#F00255, 0, 0Red
#00FF00#0F00, 255, 0Green
#0000FF#00F0, 0, 255Blue
#FFA500None255, 165, 0Orange
#808080#888128, 128, 128Gray
#1E90FFNone30, 144, 255Dodger blue
#F5F5DCNone245, 245, 220Beige
#3B82F6None59, 130, 246Interface blue

Notice that #808080 and #888 are the same color, because 8 doubles to 88. The same holds for #F00 and #FF0000. Two codes, one color, and both are valid CSS.

Design tools usually show the hex form in a color picker and the rgb form in a CSS panel. Copying either works, since the browser converts both to the same three channel values before drawing anything.

Reading hex in CSS and design tools

CSS accepts the hex code directly as a color value, and the rgb() form works the same way. A style like color: #3B82F6 and color: rgb(59, 130, 246) draw the same pixels.

The rgb() form is easier to edit by hand when you want a small shift. Raising the red channel from 59 to 79 warms the color, and lowering blue from 246 to 226 cools it. In hex, that same edit means changing 3B to 4F, which is harder to do in your head.

The hsl() form is easier for a systematic change. hsl(217, 91%, 60%) can become hsl(217, 91%, 40%) for a darker shade of the same hue, and hsl(217, 91%, 80%) for a lighter tint, without touching the channel values at all. Most design systems build their palette this way: one hue, several lightness steps.

One practical caution: a hex code does not carry a color profile. The same #3B82F6 can look slightly different on two monitors, and print work needs a CMYK conversion that a hex code cannot describe. For screen work the code is exact. For print, treat it as a starting point and check a proof.

Mistakes that produce the wrong color

Most hex mistakes are small and easy to spot once you know the shape of the notation.

When a color looks wrong, convert it back and compare the three numbers. If the numbers match what you intended, the problem is elsewhere: a CSS rule with higher priority, an opacity set on a parent element, or a background showing through a transparent color. The notation itself is rarely the culprit once the pairs are right.

The formal definition of all four hex forms, including the alpha pair, is in the W3C CSS Color Module Level 4, and the MDN reference on the hex-color data type shows the same rules with browser examples.

Frequently asked questions

How do I convert a hex code to RGB?

Split the six digits into three pairs and convert each pair from base 16. #3B82F6 is 3B = 59, 82 = 130 and F6 = 246, so the color is rgb(59, 130, 246).

What is #FFFFFF in RGB?

255, 255, 255, which is white. Each pair is FF, and FF is 15 x 16 + 15 = 255, the highest value a channel can hold.

What is #000000 in RGB?

0, 0, 0, which is black. Each pair is 00, so every channel is at its minimum.

How do I read a 3 digit hex code?

Double each digit. #F80 expands to #FF8800, which is rgb(255, 136, 0), and #38F expands to #3388FF, which is rgb(51, 136, 255).

What does the 8 digit hex code mean?

It adds an alpha pair at the end. #3B82F680 is rgb(59, 130, 246) at an alpha of 80, which is 128 out of 255, or about 50% opacity.

How much is FF in decimal?

255. The pair FF is 15 x 16 + 15 = 240 + 15 = 255, which is the top of an 8 bit channel.

What is #808080 in RGB?

128, 128, 128, a mid gray. The pair 80 is 8 x 16 + 0 = 128, and all three channels are equal, which is why the result has no hue.

How many colors can hex codes represent?

16,777,216 in the six digit form, since each of the three channels has 256 values and 256 x 256 x 256 = 16,777,216.

Is #3B82F6 the same as rgb(59, 130, 246)?

Yes, exactly the same color. The browser converts both to the same three channel values, and either notation can be used in CSS.

What is #FF0000 in RGB?

255, 0, 0, which is pure red. FF is 255 for red, and both other channels are 00.

Why does my hex color look different after adding alpha?

Because alpha lets the background show through. The same 50% alpha over white and over black produces two different visible colors, even though the six digit part is identical.

What is the contrast ratio of #3B82F6?

3.68 to 1 against white and 5.71 to 1 against black. That is below the 4.5 to 1 that WCAG asks for normal body text on white, so it suits large text or a background fill.

Can a hex code be shortened to 4 digits?

Yes. #RGBA is the shorthand of the eight digit form, so #3B8F means #33BB88FF, which is rgb(51, 187, 136) at full opacity.

What is #FFA500 in RGB?

255, 165, 0, which is orange. A5 is 10 x 16 + 5 = 165, and the red channel is at its maximum.

Spotted a wrong number or a broken result?

More Design tools

See all Design tools

Fee schedules, rates and rules change without notice. Always confirm important figures with the official source before you rely on them.