Skip to content
Hex Color Picker

RGB to Hex Converter

Type your rgb() value into the RGB box and the hex code appears beside it, ready to copy. The converter accepts rgb(220, 20, 60) or just 220 20 60, and the result is always a six-digit code in capital letters.

#DC143Cexactly crimson

For example rgb(30, 144, 255) or 30 144 255

Use 3 or 6 digits, for example #1E90FF or 19F

This is the CSS color crimson #DC143C

Pick visually and see the other formats

For example hsl(210, 100%, 56%)

For example cmyk(88%, 44%, 0%, 0%)

Recent colors

Colors you pick appear here. They stay on this device.

By the Hex Color Picker Team. Updated

How to convert RGB to hex

  • Enter the three channel values, each from 0 to 255, in the RGB box. Commas and spaces both work.
  • Read the hex code in the box beside it and press Copy.
  • Want to go the other way? Paste a hex code into the hex box and the RGB values update, because both boxes are editable.

The math, step by step

A hex code writes each channel as a two-digit base-16 number. To convert one channel, divide it by 16: the whole-number result is the first digit and the remainder is the second. Digits above 9 are the letters A to F, where A is 10 and F is 15.

Take rgb(220, 20, 60), the CSS color crimson. For red, 220 divided by 16 is 13 remainder 12, which is D and C, so red becomes DC. For green, 20 divided by 16 is 1 remainder 4, which gives 14. For blue, 60 divided by 16 is 3 remainder 12, which gives 3C. Join them with a # and you get #DC143C.

Two details that trip people up

  • Small numbers need a leading zero. A channel value of 5 is 05, not 5, so rgb(5, 5, 5) is #050505. Without the padding the code would have the wrong length.
  • Case doesn't matter to a browser: #dc143c and #DC143C are the same color. This tool outputs capitals so codes are easy to compare.

Handy values to recognize

  • rgb(255, 255, 255) is #FFFFFF, and rgb(0, 0, 0) is #000000.
  • rgb(128, 128, 128) is #808080, the middle grey. Equal channels always give a grey.
  • rgb(75, 0, 130) is #4B0082, the CSS color indigo.

Where to paste the hex code

In CSS the code goes straight into a property, for example color: #DC143C; or background-color: #DC143C;. Most design apps accept the code with or without the #, so copy whichever your tool expects. If you also need transparency, add two more digits for opacity: #DC143C80 is the same crimson at roughly 50% opacity, because 80 in hex is 128, and 128 out of 255 is about half.

Common questions

Can RGB values have decimals?

Standard 8-bit colors use whole numbers from 0 to 255, so a value like 127.5 is rounded to the nearest whole number before it becomes hex.

Is the hex code exactly the same color as the RGB value?

Yes. Hex and RGB are two ways of writing the same three numbers, so the conversion is exact in both directions.

More color tools