Hex to RGB

Paste a hex code to get its red, green and blue values, with every step of the conversion shown.

3, 4, 6 or 8 digits, with or without the #. A fourth pair is read as opacity.

RGB value

How these values are worked out

    How to convert hex to RGB by hand

    1. Split the code into pairsDrop the # and cut the six digits into three pairs. The first pair is red, the second green and the third blue.
    2. Read each digit as a number0 to 9 are themselves, and A to F stand for 10 to 15. In the pair A5, A is 10 and 5 is 5.
    3. Multiply and addMultiply the first digit by 16 and add the second: 10 × 16 + 5 = 165. Do this for all three pairs.

    Going the other way? Use RGB to hex. For HSL, CMYK and the other codes of a color, type it into the color picker.

    Hex digits

    Hexadecimal counts in sixteens, so it has sixteen digits. After 9 come the letters A to F. Two hex digits cover every value from 0 to 255: 00 is 0 and FF is 15 × 16 + 15 = 255.

    Hex digit0123456789ABCDEF
    Value0123456789101112131415

    The 16 basic web colors in hex and RGB

    ColorHexRGB
    Black#0000000, 0, 0
    Gray#808080128, 128, 128
    Silver#C0C0C0192, 192, 192
    White#FFFFFF255, 255, 255
    Maroon#800000128, 0, 0
    Red#FF0000255, 0, 0
    Olive#808000128, 128, 0
    Yellow#FFFF00255, 255, 0
    Green#0080000, 128, 0
    Lime#00FF000, 255, 0
    Teal#0080800, 128, 128
    Aqua (cyan)#00FFFF0, 255, 255
    Navy (navy blue)#0000800, 0, 128
    Blue#0000FF0, 0, 255
    Purple#800080128, 0, 128
    Fuchsia#FF00FF255, 0, 255

    Questions

    How do I convert hex to RGB?

    Split the six digits into three pairs: red, green and blue. In each pair, multiply the first digit by 16 and add the second, counting A to F as 10 to 15. #FFA500 gives 255, 165 and 0, so it is rgb(255, 165, 0).

    What is #FFFFFF in RGB?

    rgb(255, 255, 255), which is white. #000000 is rgb(0, 0, 0), which is black.

    How do I read a three-digit hex code?

    Double each digit first. #FA0 becomes #FFAA00, which is rgb(255, 170, 0).

    What does an eight-digit hex code mean?

    The last pair is the opacity, also called alpha. 00 is fully see-through and FF is solid. #FFA50080 is orange at about 50% opacity, because 80 in hex is 128 and 128 out of 255 is about half.

    Is anything lost in the conversion?

    No. A hex code and its RGB value hold the same three numbers, one counted in sixteens and one in tens. You can convert back and forth as often as you like.

    What do the letters A to F stand for?

    The values 10 to 15. Hexadecimal counts in sixteens, so it needs six digits more than the usual ten.

    How do I write an RGB color in CSS?

    As rgb(255, 165, 0) or, in the newer form without commas, rgb(255 165 0). With transparency, add the opacity after a slash: rgb(255 165 0 / 50%).

    How do I get values from 0 to 1?

    Divide each value by 255. Some design and 3D tools want colors this way: rgb(255, 165, 0) becomes 1, 0.647, 0.

    More color tools