How do you convert HEX to RGB?
Split the six hex digits into three pairs (red, green, blue) and convert each pair from base 16 to base 10: multiply the first digit by 16 and add the second. Hex digits A to F stand for 10 to 15. Each result is a value from 0 to 255.
Example: #1E90FF
| Channel | Hex pair | Calculation | Decimal |
|---|---|---|---|
| Red | 1E | 1 × 16 + 14 | 30 |
| Green | 90 | 9 × 16 + 0 | 144 |
| Blue | FF | 15 × 16 + 15 | 255 |
So #1E90FF = rgb(30, 144, 255).
What is the HEX to RGB formula?
R = 16 × d1 + d2, using the 1st and 2nd hex digits
G = 16 × d3 + d4
B = 16 × d5 + d6
How do you convert HEX to RGBA?
An 8-digit hex code such as #1E90FF80 adds a fourth pair for alpha. Convert it like the others and divide by 255: 80 hex = 128, and 128 / 255 ≈ 0.5, so the color is rgba(30, 144, 255, 0.5). A 6-digit code is fully opaque (alpha 1). The 8-digit form is defined in W3C, CSS Color Module Level 4 and works in all current browsers.
What about 3-digit hex codes?
Shorthand codes repeat each digit: #39F means #3399FF, which is rgb(51, 153, 255). A 4-digit code such as #39F8 adds a shorthand alpha digit.
How do I convert HEX to RGB in JavaScript, Python or CSS?
// JavaScript
const hex = "1E90FF";
const [r, g, b] = [0, 2, 4].map(i => parseInt(hex.slice(i, i + 2), 16)); // 30, 144, 255
# Python
h = "1E90FF"
r, g, b = (int(h[i:i + 2], 16) for i in (0, 2, 4)) # 30, 144, 255
In CSS you rarely need to convert at all: color: #1E90FF and color: rgb(30 144 255) are the same color. For transparency use rgb(30 144 255 / 50%) or the 8-digit hex form.
Common hex colors in RGB
| HEX | RGB | CMYK | Name | |
|---|---|---|---|---|
#FFFFFF | 255, 255, 255 | 0, 0, 0, 0 | white | |
#000000 | 0, 0, 0 | 0, 0, 0, 100 | black | |
#FF0000 | 255, 0, 0 | 0, 100, 100, 0 | red | |
#00FF00 | 0, 255, 0 | 100, 0, 100, 0 | lime | |
#0000FF | 0, 0, 255 | 100, 100, 0, 0 | blue | |
#FFFF00 | 255, 255, 0 | 0, 0, 100, 0 | yellow | |
#00FFFF | 0, 255, 255 | 100, 0, 0, 0 | aqua | |
#FF00FF | 255, 0, 255 | 0, 100, 0, 0 | fuchsia | |
#808080 | 128, 128, 128 | 0, 0, 0, 50 | gray | |
#FFA500 | 255, 165, 0 | 0, 35, 100, 0 | orange | |
#800080 | 128, 0, 128 | 0, 100, 0, 50 | purple | |
#008080 | 0, 128, 128 | 100, 0, 0, 50 | teal | |
#1E90FF | 30, 144, 255 | 88, 44, 0, 0 | dodgerblue | |
#2E8B57 | 46, 139, 87 | 67, 0, 37, 45 | seagreen | |
#FF5733 | 255, 87, 51 | 0, 66, 80, 0 |
Color Code Converter · RGB to HEX Converter · CMYK to RGB Converter · RGB to CMYK Converter
Formulas checked October 2026 against W3C, CSS Color Module Level 4.