Skip to content
PictureToLink logoPictureToLink
Menu

Hex to RGB converter

The hex code #4A90E2 is rgb(74, 144, 226). Paste any hex color code to get its RGB values. The converter reads 3-digit shorthand (#333), 6-digit codes and 8-digit codes with an alpha channel, and shows the CSS rgba() string, the modern slash syntax and HSL.

Change any value and the result updates as you type.

3, 6 or 8 hex digits, with or without the #

CSS rgb()

rgb(74, 144, 226)

Red
744A = 4 × 16 + 10 = 74
Green
14490 = 9 × 16 + 0 = 144
Blue
226E2 = 14 × 16 + 2 = 226
CSS rgba()
rgba(74, 144, 226, 1)Fully opaque; change the last number for transparency
Modern CSS
rgb(74 144 226)
HSL
hsl(212, 72%, 59%)
Normalised hex
#4A90E2
Each hex pair as decimal and percent
ChannelDecimalHexPercent
Red744A29%
Green1449056.5%
Blue226E288.6%

Calculated in your browser; nothing you type is sent or stored. Spotted a wrong result? Tell us.

By Ahsan Khowaja (CEO) · Updated 10 November 2026

On this page

How to use the hex to RGB converter

  1. Paste or type the hex code. The # is optional, so 4A90E2, #4a90e2 and 0x4A90E2 all work.
  2. Read the result: rgb(74, 144, 226). The red, green and blue values are also listed one by one, with the arithmetic for each pair underneath.
  3. Copy the form you need. The rgba() row is ready for a transparent version, the "modern CSS" row uses the space-separated syntax, and the HSL row gives the hue, saturation and lightness.

An invalid code gets a plain error, never a wrong color. Usually it's a letter outside A to F, or a length other than 3, 4, 6 or 8 digits. To go from numbers to a code, use the RGB to hex converter.

How to read a hex color code

A six-digit code is three pairs: #RRGGBB. Red comes first, then green, then blue. Each pair is a number from 0 to 255 written in hexadecimal (base 16), which counts 0, 1, 2 … 9, A, B, C, D, E, F before it needs a second digit. A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15.

So #4A90E2 splits into 4A (red), 90 (green) and E2 (blue). Higher pairs mean more of that light. E2 is a high blue and 4A a low red, which is why the color is a sky blue.

The hex to RGB formula

For each pair, multiply the first digit by 16 and add the second digit:

  • 4A: 4 × 16 + 10 = 74
  • 90: 9 × 16 + 0 = 144
  • E2: 14 × 16 + 2 = 226

Together they make rgb(74, 144, 226). At the top end, FF is 15 × 16 + 15 = 255, and at the bottom 00 is 0. That's the whole method. We run it for you and prints the working under each channel.

Worked examples

Hex codePairsRGB
#4A90E24A = 74, 90 = 144, E2 = 226rgb(74, 144, 226)
#DC143C (crimson)DC = 13 × 16 + 12 = 220, 14 = 20, 3C = 60rgb(220, 20, 60)
#008080 (teal)00 = 0, 80 = 8 × 16 = 128, 80 = 128rgb(0, 128, 128)
#C0C0C0 (silver)C0 = 12 × 16 = 192, three timesrgb(192, 192, 192)
#333shorthand for #333333: 33 = 3 × 16 + 3 = 51rgb(51, 51, 51)
#FF000080FF = 255, 00, 00, then 80 = 128 is alphargba(255, 0, 0, 0.5)

Three-digit shorthand and eight-digit alpha

A 3 digit hex code such as #333 or #FC0 is shorthand, and each digit is doubled to make the full code. #333 is #333333 and #FC0 is #FFCC00. You'll see the six-digit form it was expanded to. Shorthand exists only for colors whose pairs are doubled digits, so #4A90E2 cannot be shortened. Don't try it by hand: #49E would expand to #4499EE, a different blue.

An 8 digit hex color adds a fourth pair for alpha (opacity): #RRGGBBAA. 00 is fully transparent and FF fully opaque. Divide the alpha pair's value by 255 to convert it. 80 is 128 ÷ 255 = 0.502, so #FF000080 is a red at about 50% opacity, written rgba(255, 0, 0, 0.5). A 4-digit shorthand exists too (#F008 = #FF000088). Eight-digit codes are part of CSS Color Level 4, and all current browsers support them (MDN: hex color).

Most people who search for hex to rgba have a different job, though. They hold a brand color as a six-digit code and need it at 20% for a hover background. Convert it here, then set the last number yourself: rgba(74, 144, 226, 0.2).

Hex to RGB in CSS: which form to use

In CSS, #4A90E2, rgb(74, 144, 226), rgb(74 144 226) and rgba(74, 144, 226, 1) are the same color, and rgba() is now an alias of rgb() (MDN: rgb()). Pick the RGB form in three cases:

  • You need transparency and want it readable: rgb(74 144 226 / 20%) says what it does.
  • You keep channels in custom properties: --brand: 74 144 226; then rgb(var(--brand) / 0.5).
  • You're feeding a canvas, WebGL or image-processing code that wants numbers, not strings.

Otherwise use hex. It's shorter, and most code bases use it for solid colors. Neither form can express a wide-gamut Display P3 color, though, because both are 8-bit sRGB. For that, CSS has color(display-p3 r g b).

Common web colors in hex and RGB

Gray scales and a handful of CSS named colors turn up in almost every stylesheet. Each row below is converted with the formula above.

HexRGBTypical use
#333333rgb(51, 51, 51)Body text on white
#666666rgb(102, 102, 102)Secondary text
#999999rgb(153, 153, 153)Placeholders, disabled text
#CCCCCCrgb(204, 204, 204)Borders, dividers
#F5F5F5rgb(245, 245, 245)Page backgrounds (whitesmoke)
#708090rgb(112, 128, 144)slategray
#663399rgb(102, 51, 153)rebeccapurple
#6A5ACDrgb(106, 90, 205)slateblue
#2E8B57rgb(46, 139, 87)seagreen
#FF7F50rgb(255, 127, 80)coral
#FFD700rgb(255, 215, 0)gold
#DC143Crgb(220, 20, 60)crimson

Named colors are fixed by the CSS named-color list, so teal always means #008080.

Hex to RGB percentage

CSS also accepts channels as percentages: rgb(29% 56.5% 88.6%). Divide each channel by 255 and multiply by 100 to get them. For #4A90E2 that is 74 ÷ 255 = 29.0%, 144 ÷ 255 = 56.5% and 226 ÷ 255 = 88.6%. Our per-channel table in the result shows the percentages beside the decimal values. They are handy for shader code and for design tools that show channels as 0–1 or 0–100%.

Hex to HSL

Hue, saturation and lightness describe the same color in a different way. Take #4A90E2 and scale the channels to 0–1 (0.290, 0.565, 0.886).

  • Lightness is the average of the highest and lowest channels: (0.886 + 0.290) ÷ 2 = 0.588, so 59%.
  • Saturation is the range (0.596) divided by 1 − |2L − 1| = 0.824, which gives 0.72, so 72%.
  • Hue depends on which channel is highest. Here it is blue, so the hue is 60° × ((R − G) ÷ range + 4) = 60 × 3.539 ≈ 212°.

So the result is hsl(212, 72%, 59%). Grays like #333 have no hue or saturation, so they come out as hsl(0, 0%, 20%).

Hex to RGB in JavaScript and Python

For one color, the converter is quickest. For a batch, these short versions apply the same formula. Neither checks its input, so a typo like #4A9OE2 (a letter O) gives a wrong answer instead of an error.

JavaScript reads the six digits as one number and splits it with bit shifts:

const hexToRgb = (hex) => {
  const n = parseInt(hex.replace('#', ''), 16);
  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
};
hexToRgb('#4A90E2'); // [74, 144, 226]

Python converts each pair with int(pair, 16):

h = '#4A90E2'.lstrip('#')
tuple(int(h[i:i + 2], 16) for i in (0, 2, 4))  # (74, 144, 226)

Both expect a six-digit code. Expand 3-digit shorthand first, and take the last pair off an 8-digit code as alpha.

What the numbers don't tell you

RGB values from a hex code assume the sRGB color space, which browsers use by default. But if the code came from a photo in Display P3 or Adobe RGB, the same numbers describe a stronger color there. Our guide to sRGB vs Adobe RGB vs Display P3 explains what to do if colors shift after upload.

A hex code also says nothing about whether text in that color can be read. Run the result through the color contrast checker before you use it for text.

Questions and answers

How do I convert hex to RGB manually?

Split the code into three pairs. For each pair, multiply the first digit by 16 and add the second, counting A to F as 10 to 15. #4A90E2 gives 4 × 16 + 10 = 74, 9 × 16 + 0 = 144 and 14 × 16 + 2 = 226, so rgb(74, 144, 226).

What is #4A90E2 in RGB?

rgb(74, 144, 226), a sky blue common in interface design. In HSL it's hsl(212, 72%, 59%), and at 20% opacity it's rgba(74, 144, 226, 0.2).

What does the 3-digit hex code #333 mean?

It is shorthand for #333333. Each digit is doubled, so 3 becomes 33, which is 3 × 16 + 3 = 51. That gives rgb(51, 51, 51), a dark gray often used for body text.

How do I convert an 8-digit hex color to rgba?

First six digits are the color, last two the alpha. Convert the color pairs as usual, then divide the alpha pair by 255. #FF000080 is red with alpha 128 ÷ 255 = 0.5, so rgba(255, 0, 0, 0.5).

Why does the converter say my code is invalid?

A hex color may only contain the digits 0–9 and the letters A–F, and must be 3, 4, 6 or 8 digits long, not counting the #. Codes like #GGG and #12345 aren't valid, and neither is a color name such as "blue". Check for a letter O typed in place of a zero.

Is hex to RGB exact?

Yes. Every six-digit hex code maps to exactly one rgb() triple and back with no rounding, because both hold the same 256 levels per channel. Only the HSL and percentage forms are rounded for display.

All image, photo and design calculators