Hex to RGB Converter Guide: Convert Hex Color Codes to RGB Values

By Risetop Team · Published April 15, 2026 · 6 min read

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.

Understanding Hex Color Codes

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.

Short Hex Codes

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.

Understanding RGB Color Values

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.

How to Convert Hex to RGB Manually

The conversion is straightforward. For each two-digit hex pair, convert from hexadecimal (base-16) to decimal (base-10):

Step-by-Step Example: Convert #8b5cf6

Red: 8B

Green: 5C

Blue: F6

Result: #8b5cf6 = rgb(139, 92, 246)

Quick tip: For the conversion, multiply the first digit by 16 and add the second digit's decimal value. That's it. You only need to do this three times — once for each color channel.

Converting RGB Back to Hex

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

When to Use Hex vs RGB

SituationRecommended FormatWhy
CSS stylesheetsEither (hex is more common)Both are fully supported
Inline stylesHexMore compact: 7 chars vs 15+
JavaScript / CanvasRGBCanvas API requires separate R, G, B values
Design tools (Figma, Sketch)HexStandard format for copy-paste
Needing transparencyRGBAHex alpha (#RRGGBBAA) has limited support
Python / PIL / MatplotlibRGB tupleLibraries expect (R, G, B) numbers
Android developmentHexAndroid XML resources use hex format
iOS / SwiftRGBUIColor uses CGFloat values

Adding Transparency: RGBA and Hex Alpha

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.

Common Color Conversions Reference

ColorHexRGBPreview
Black#000000rgb(0, 0, 0)
White#FFFFFFrgb(255, 255, 255)
Red#FF0000rgb(255, 0, 0)
Green#00FF00rgb(0, 255, 0)
Blue#0000FFrgb(0, 0, 255)
Purple#8B5CF6rgb(139, 92, 246)
Orange#F97316rgb(249, 115, 22)
Cyan#06B6D4rgb(6, 182, 212)
Pink#EC4899rgb(236, 72, 153)
Dark Gray#374151rgb(55, 65, 81)

Using Colors in CSS: Practical Tips

Consistency Across Your Project

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.

CSS Custom Properties

: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.

Color Manipulation in JavaScript

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

How to Use Our Hex to RGB Converter

Our online Hex to RGB Converter handles conversions instantly in both directions:

  1. Enter a hex code — type #8b5cf6 (with or without the #) to get the RGB equivalent
  2. Or enter RGB values — type 139, 92, 246 to get the hex equivalent
  3. See the result — the conversion appears instantly with a live color preview
  4. Copy with one click — buttons let you copy the result in CSS-ready format

The tool also shows HSL values, so you can quickly get the color in all three common web formats without running a separate conversion.

Understanding HSL: The Third Format

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.

Common Mistakes

Conclusion

Hex 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 →