If you've ever copied a color from a design tool and needed to use it in a different application, you've run into the hex-to-RGB conversion problem. One tool gives you #8b5cf6, another wants rgb(139, 92, 246). This guide explains how these color formats work, how to convert between them, and when to use each one. We'll also introduce our free Hex to RGB Converter for instant conversions.
A hex color code (short for hexadecimal) is a six-digit code preceded by a hash symbol that represents a color. It's the most common color format on the web. The code #8b5cf6 breaks down as follows:
#8b5cf6
│││ │││
│││ └└└── Blue channel: F6 (246 in decimal)
│└└────── Green channel: 5C (92 in decimal)
└└─────── Red channel: 8B (139 in decimal)
Each pair of characters represents one of the three primary color channels — red, green, and blue — on a scale from 00 (0, no color) to FF (255, full intensity). Hexadecimal is base-16, meaning it uses digits 0-9 and letters A-F to represent values 0-15.
You'll sometimes see three-character hex codes like #F00. This is shorthand where each digit is doubled: #F00 becomes #FF0000, which is pure red. It only works when both digits in each pair are identical, so #8b5cf6 can't be shortened.
RGB stands for Red, Green, Blue. An RGB value specifies each color channel as a number from 0 to 255, where 0 means the channel is off and 255 means it's at full intensity.
rgb(139, 92, 246)
│ │ │
│ │ └── Blue: 246
│ └─────── Green: 92
└──────────── Red: 139
RGB is intuitive because the numbers map directly to intensity. rgb(255, 0, 0) is pure red, rgb(0, 255, 0) is pure green, rgb(0, 0, 255) is pure blue, and rgb(255, 255, 255) is white. rgb(0, 0, 0) is black — all channels off.
The conversion is straightforward. For each two-digit hex pair, convert from hexadecimal (base-16) to decimal (base-10):
Red: 8B
Green: 5C
Blue: F6
Result: #8b5cf6 = rgb(139, 92, 246)
To reverse the process, divide each value by 16. The quotient is the first hex digit, and the remainder is the second:
139 ÷ 16 = 8 remainder 11 → 8B
92 ÷ 16 = 5 remainder 12 → 5C
246 ÷ 16 = 15 remainder 6 → F6
Result: rgb(139, 92, 246) = #8b5cf6
| Situation | Recommended Format | Why |
|---|---|---|
| CSS stylesheets | Either (hex is more common) | Both are fully supported |
| Inline styles | Hex | More compact: 7 chars vs 15+ |
| JavaScript / Canvas | RGB | Canvas API requires separate R, G, B values |
| Design tools (Figma, Sketch) | Hex | Standard format for copy-paste |
| Needing transparency | RGBA | Hex alpha (#RRGGBBAA) has limited support |
| Python / PIL / Matplotlib | RGB tuple | Libraries expect (R, G, B) numbers |
| Android development | Hex | Android XML resources use hex format |
| iOS / Swift | RGB | UIColor uses CGFloat values |
Sometimes you need a color with transparency. Both formats support this:
/* RGBA - fourth value is opacity (0 to 1) */
rgba(139, 92, 246, 0.5) /* 50% transparent */
/* Hex with alpha - fourth pair is opacity (00 to FF) */
#8b5cf680 /* 80 in hex ≈ 50% transparent */
The hex alpha format (#RRGGBBAA) is supported in modern browsers and CSS, but RGBA is more widely compatible and more readable — it's much easier to understand 0.5 than 80 in hex when thinking about opacity percentages.
| Color | Hex | RGB | Preview |
|---|---|---|---|
| Black | #000000 | rgb(0, 0, 0) | |
| White | #FFFFFF | rgb(255, 255, 255) | |
| Red | #FF0000 | rgb(255, 0, 0) | |
| Green | #00FF00 | rgb(0, 255, 0) | |
| Blue | #0000FF | rgb(0, 0, 255) | |
| Purple | #8B5CF6 | rgb(139, 92, 246) | |
| Orange | #F97316 | rgb(249, 115, 22) | |
| Cyan | #06B6D4 | rgb(6, 182, 212) | |
| Pink | #EC4899 | rgb(236, 72, 153) | |
| Dark Gray | #374151 | rgb(55, 65, 81) |
Pick one format and stick with it. Mixing #8b5cf6 and rgb(139, 92, 246) in the same stylesheet makes it harder to search for and modify colors. Most teams standardize on hex for solid colors and RGBA for anything with transparency.
:root {
--color-primary: #8b5cf6;
--color-primary-rgb: 139, 92, 246;
}
.button {
background: var(--color-primary);
}
.overlay {
background: rgba(var(--color-primary-rgb), 0.5);
}
This pattern stores the RGB values separately so you can easily create transparent variants without converting anything.
When you need to programmatically lighten, darken, or blend colors, RGB is far easier to work with than hex. Each channel is a simple number you can add, subtract, or interpolate between:
function lighten(rgb, amount) {
return rgb.map(v => Math.min(255, v + amount));
}
lighten([139, 92, 246], 30);
// → [169, 122, 255] — a lighter purple
Our online Hex to RGB Converter handles conversions instantly in both directions:
#8b5cf6 (with or without the #) to get the RGB equivalent139, 92, 246 to get the hex equivalentThe tool also shows HSL values, so you can quickly get the color in all three common web formats without running a separate conversion.
While you're here, it's worth knowing about HSL (Hue, Saturation, Lightness) — another common color format that's often more intuitive than hex or RGB:
hsl(258, 91%, 66%)
│ │ │
│ │ └── Lightness: 66% (how light/dark)
│ └─────── Saturation: 91% (how vivid)
└──────────── Hue: 258° (position on the color wheel)
HSL is particularly useful when you want to create color variations — adjusting the lightness value by 10% gives you a predictable lighter or darker shade, which is much harder to do in hex or RGB without a converter.
8b5cf6 won't work, it must be #8b5cf6#8b5cf6 and #8B5CF6 are identical; CSS is case-insensitive for color values#8b5cf680 has an alpha channel; converting just the first 6 characters loses the transparency infoHex and RGB are two sides of the same coin — they represent exactly the same information in different formats. Knowing how to convert between them and when to use each one is a basic but essential skill for anyone working with colors in web design, development, or digital media.
Stop doing mental math or hunting for conversion formulas. Our free Hex to RGB Converter handles it all instantly, with color previews and one-click copy for both CSS formats.
Try the Hex to RGB Converter →