How to Convert HEX to RGB (and Back)
A HEX color like #FF6B57 and an RGB color like rgb(255, 107, 87) describe the exact same color. HEX packs the three channels into a six-digit hexadecimal string; RGB writes them as three decimal numbers from 0 to 255. Converting between them is direct arithmetic.
The formula
A HEX code is three pairs of hex digits: red, green, blue. Convert each pair from base-16 to base-10.
#FF6B57
FF -> 255 (15 × 16 + 15)
6B -> 107 (6 × 16 + 11)
57 -> 87 (5 × 16 + 7)
= rgb(255, 107, 87)
To go the other way, convert each decimal channel to a two-digit hex value and pad with a leading zero when needed (so 7 becomes 07).
Reference table
| HEX | RGB | Color |
|---|---|---|
#000000 |
rgb(0, 0, 0) |
Black |
#FFFFFF |
rgb(255, 255, 255) |
White |
#FF0000 |
rgb(255, 0, 0) |
Red |
#00FF00 |
rgb(0, 255, 0) |
Green |
#0000FF |
rgb(0, 0, 255) |
Blue |
#FF6B57 |
rgb(255, 107, 87) |
Coral |
Shorthand and alpha
Three-digit HEX is shorthand where each digit is doubled: #F60 expands to #FF6600. For transparency, use eight-digit HEX (#FF6B57CC) or rgba(255, 107, 87, 0.8), where the final value is opacity from 0 to 1.
When to use HEX vs RGB
- HEX is compact and the most common format in design tools and CSS.
- RGB / RGBA is easier to manipulate in JavaScript and is required when you need an alpha channel via
rgba(). - Modern CSS also accepts
rgb(255 107 87 / 80%)with space separators, which many teams now prefer.
Convert colors in your browser
The free Color Picker shows HEX, RGB, and HSL side by side and updates all three as you adjust a color. Nothing is uploaded, and you can copy any format with one click. It is the fastest way to grab a value when you only have one format and need another.