RGB to hex

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

Red, green and blue, 0 to 255

Hex code

How this code is worked out

    How to convert RGB to hex by hand

    1. Divide by 16Take the red value and divide it by 16. Keep the whole number and the remainder: 165 ÷ 16 is 10, remainder 5.
    2. Write both as hex digits0 to 9 stay as they are, and 10 to 15 become A to F. So 10 and 5 are written A5.
    3. Join the three pairsDo the same for green and blue, then write red, green and blue in that order behind a #.

    Going the other way? Use hex to RGB. 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 RGB and hex

    ColorRGBHex
    Black0, 0, 0#000000
    Gray128, 128, 128#808080
    Silver192, 192, 192#C0C0C0
    White255, 255, 255#FFFFFF
    Maroon128, 0, 0#800000
    Red255, 0, 0#FF0000
    Olive128, 128, 0#808000
    Yellow255, 255, 0#FFFF00
    Green0, 128, 0#008000
    Lime0, 255, 0#00FF00
    Teal0, 128, 128#008080
    Aqua (cyan)0, 255, 255#00FFFF
    Navy (navy blue)0, 0, 128#000080
    Blue0, 0, 255#0000FF
    Purple128, 0, 128#800080
    Fuchsia255, 0, 255#FF00FF

    Questions

    How do I convert RGB to hex?

    Divide each of the three values by 16. Write the whole number and the remainder as hex digits, where 10 to 15 become A to F. Join the three pairs and put a # in front. For 255, 165, 0 the pairs are FF, A5 and 00, so the code is #FFA500.

    What is rgb(255, 255, 255) in hex?

    #FFFFFF, which is white. Each 255 becomes FF, the largest two-digit hex number. Black, rgb(0, 0, 0), is #000000.

    Is a hex code the same color as its RGB value?

    Yes. Both give the same three amounts of red, green and blue, one counted in sixteens and one in tens. Nothing is rounded, so no color is lost in either direction.

    Why do hex codes use letters?

    Hexadecimal counts in sixteens, so it needs sixteen digits. After 0 to 9 come A, B, C, D, E and F, which stand for 10 to 15. Two hex digits cover 0 to 255, exactly the range of one color value.

    Does it matter if the letters are capitals?

    No. #ffa500 and #FFA500 are the same color in CSS, HTML and design tools.

    What is a three-digit hex code?

    A short form for codes whose pairs are doubled digits. #FA0 means #FFAA00: each digit is written twice. Only codes like that can be shortened.

    How do I convert an RGB color with transparency?

    Add a fourth pair for the opacity. Multiply the opacity by 255 and convert the result like a color value: 50% gives 128, which is 80 in hex, so rgb(255 165 0 / 50%) is #FFA50080.

    What if my values are percentages?

    Multiply each percentage by 2.55 and round to a whole number first. 100% is 255 and 50% is 128. You can also paste a value with percentages into the field here.

    More color tools