Hex to RGB Converter
Hex
RGB
Hex to RGB Conversion
Hexadecimal colors use base-16 notation with values from 00 to FF for each channel, while RGB (specifically RGB255) uses decimal values from 0-255. They both represent the same range of colors, just in different formats.
For example, the hex color #ff0000
(pure red) converts to the
RGB color rgb(255, 0, 0)
.
Algorithm to convert Hex to RGB
To convert hex to RGB, each pair of hexadecimal digits is converted from base-16 to base-10 (decimal):
- Take the first two characters (red channel) and convert from hex to decimal.
- Take the middle two characters (green channel) and convert from hex to decimal.
- Take the last two characters (blue channel) and convert from hex to decimal.
- Format as
rgb(red, green, blue)
For hex colors with alpha transparency (#RRGGBBAA
), the last
two characters represent the alpha channel, which is converted to a decimal
value between 0-255 and then normalized to 0-1 for the RGBA format.
Short hex notation
Hex colors can also be written in short 3-digit notation when each channel has identical digits. For example:
#f00
expands to#ff0000
→rgb(255, 0, 0)
#0f0
expands to#00ff00
→rgb(0, 255, 0)
#abc
expands to#aabbcc
→rgb(170, 187, 204)
Similarly, there is a short hex notation for colors with transparency, using
4-digit hex codes (e.g., #RGBA
).
#f00d
expands to#ff0000dd
→rgb(255, 0, 0, 0.867)
Our converter automatically handles 3, 4, 6, and 8 digit hex codes, expanding short notation as needed.
Common Hex to RGB conversions
Here are some frequently converted colors:
#ffffff
→rgb(255, 255, 255)
(white)#000000
→rgb(0, 0, 0)
(black)#ff0000
→rgb(255, 0, 0)
(red)#00ff00
→rgb(0, 255, 0)
(green)#0000ff
→rgb(0, 0, 255)
(blue)#808080
→rgb(128, 128, 128)
(gray)
Need to convert the other way? Use our RGB to Hex Converter to convert RGB values to hexadecimal color codes.