By Ahsan Khowaja (CEO) · Updated 10 November 2026
On this page
- How to use the hex to RGB converter
- How to read a hex color code
- The hex to RGB formula
- Worked examples
- Three-digit shorthand and eight-digit alpha
- Hex to RGB in CSS: which form to use
- Common web colors in hex and RGB
- Hex to RGB percentage
- Hex to HSL
- Hex to RGB in JavaScript and Python
- What the numbers don't tell you
- Questions and answers
- Related calculators
How to use the hex to RGB converter
- Paste or type the hex code. The
#is optional, so4A90E2,#4a90e2and0x4A90E2all work. - 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. - 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 = 7490: 9 × 16 + 0 = 144E2: 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 code | Pairs | RGB |
|---|---|---|
| #4A90E2 | 4A = 74, 90 = 144, E2 = 226 | rgb(74, 144, 226) |
| #DC143C (crimson) | DC = 13 × 16 + 12 = 220, 14 = 20, 3C = 60 | rgb(220, 20, 60) |
| #008080 (teal) | 00 = 0, 80 = 8 × 16 = 128, 80 = 128 | rgb(0, 128, 128) |
| #C0C0C0 (silver) | C0 = 12 × 16 = 192, three times | rgb(192, 192, 192) |
| #333 | shorthand for #333333: 33 = 3 × 16 + 3 = 51 | rgb(51, 51, 51) |
| #FF000080 | FF = 255, 00, 00, then 80 = 128 is alpha | rgba(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;thenrgb(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.
| Hex | RGB | Typical use |
|---|---|---|
| #333333 | rgb(51, 51, 51) | Body text on white |
| #666666 | rgb(102, 102, 102) | Secondary text |
| #999999 | rgb(153, 153, 153) | Placeholders, disabled text |
| #CCCCCC | rgb(204, 204, 204) | Borders, dividers |
| #F5F5F5 | rgb(245, 245, 245) | Page backgrounds (whitesmoke) |
| #708090 | rgb(112, 128, 144) | slategray |
| #663399 | rgb(102, 51, 153) | rebeccapurple |
| #6A5ACD | rgb(106, 90, 205) | slateblue |
| #2E8B57 | rgb(46, 139, 87) | seagreen |
| #FF7F50 | rgb(255, 127, 80) | coral |
| #FFD700 | rgb(255, 215, 0) | gold |
| #DC143C | rgb(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.
