How to Convert HEX to RGB
Enter a HEX color and read its red, green and blue channels. Each pair is interpreted as a base-16 byte. Copy the CSS-ready RGB value and check the swatch before replacing a stylesheet value.
3-Digit vs 6-Digit HEX Colors
Three-digit HEX duplicates each digit: #abc expands to #aabbcc. Six-digit HEX explicitly provides two digits per channel. Four- and eight-digit forms also carry alpha when supported by the tool.
RGB Channels and Alpha Values
RGB channels use integers from 0 to 255. Alpha is independent and ranges from fully transparent to fully opaque. In eight-digit HEX the final pair represents opacity, not a fourth color channel.
HEX to RGB Examples
#FF8000 becomes rgb(255, 128, 0). #fff expands to #ffffff and becomes white. Keeping leading zeroes is essential for correct channel grouping in a six-digit code.
Using RGB in CSS
Use RGB when channel values or alpha are convenient in your stylesheet. A transparent color blends with the background, so validate its appearance in context rather than judging the isolated swatch.
More examples and technical details
How to Convert HEX to RGB by Hand
A HEX color code looks cryptic at first, but it is just three numbers wearing a disguise. The hash is decoration, and the six characters after it are three pairs of hex digits, one pair each for red, green, and blue. Converting to RGB means turning each pair from base 16 back into an ordinary decimal number between 0 and 255.
The routine is short:
- Drop the leading hash and take the six remaining characters.
- Split them into three pairs: the first pair is red, the second green, the third blue.
- Convert each pair from base 16 to decimal. The left digit counts sixteens, the right digit counts ones.
- Write the three results as rgb(red, green, blue).
Worked example: #FF5733
Split into FF, 57, 33 and convert each pair:
The letters A through F simply stand for 10 through 15, so F is 15 and FF works out to (15 x 16) + 15 = 255, the maximum any channel can reach.
Shorthand Three Digit HEX
You will often see three digit HEX codes like #F53. This is a shorthand that CSS expands by doubling every digit, so #F53 becomes #FF5533. The shorthand only works when both digits of each pair are identical, which is why it can only express 4,096 of the 16 million possible colors. When you convert a three digit code, expand it first, then treat it exactly like a normal six digit code.
Where You Actually Need RGB
If HEX is so compact, why convert at all? Because plenty of contexts want the raw channel numbers. CSS rgba() is the classic case: to fade a color to fifty percent opacity you need rgba(255, 87, 51, 0.5), and there is no way to add that alpha to a plain HEX color without switching notations. The HTML canvas API expects RGB style strings for its fillStyle and strokeStyle. SVG attributes, WebGL, and most image manipulation code all work in RGB because the individual numbers are what the math operates on. Whenever you need to reason about or animate a single channel, RGB is the format that gives you direct access to it.
Named Color Reference
CSS ships with a set of keyword colors you can write by name instead of a code. They map to exact HEX and RGB values, so the table below is handy when you want to sanity check a conversion or reach for a familiar color without opening a picker.
| Name | HEX | RGB |
|---|---|---|
| black | #000000 | rgb(0, 0, 0) |
| white | #FFFFFF | rgb(255, 255, 255) |
| red | #FF0000 | rgb(255, 0, 0) |
| green | #008000 | rgb(0, 128, 0) |
| blue | #0000FF | rgb(0, 0, 255) |
| yellow | #FFFF00 | rgb(255, 255, 0) |
| cyan | #00FFFF | rgb(0, 255, 255) |
| magenta | #FF00FF | rgb(255, 0, 255) |
| silver | #C0C0C0 | rgb(192, 192, 192) |
| gray | #808080 | rgb(128, 128, 128) |
| orange | #FFA500 | rgb(255, 165, 0) |
| purple | #800080 | rgb(128, 0, 128) |
| teal | #008080 | rgb(0, 128, 128) |
| navy | #000080 | rgb(0, 0, 128) |
Need a different color task? Browse every free developer tool including color converters, encoders, and hashing utilities.
Frequently asked questions
How do I convert a HEX color to RGB?
Read each hexadecimal pair as a byte, or enter the code here for the RGB output.
Does #fff equal #ffffff?
Yes. Each shorthand digit is repeated, so both represent white.
Can HEX include alpha transparency?
Yes. Four- and eight-digit forms append alpha information.
What RGB range is valid?
Each red, green and blue channel ranges from 0 to 255.
Is conversion client-side?
Yes. Color conversion runs in the browser.