RGB to Hex Converter

Convert RGB values into a hex color code.

This is the reverse conversion. Enter separate red, green, and blue values from 0 to 255, and it produces the matching six character hex code. It's the one you reach for when you've got RGB values from a color picker or a spec sheet, but need a compact hex code for a stylesheet.

How to use it

  1. Enter the red value, 0 to 255, in the first field.
  2. Enter the green and blue values in the next two fields.
  3. The hex code updates automatically as you change any value.
  4. Check the swatch to see if it's the shade you expected.
  5. Copy the hex code.

When it helps

  • Converting RGB values sampled from a photo into a hex code for a CSS variable.
  • Turning RGB colors from a design brief into the hex format your stylesheet needs.
  • Matching a brand color between print, which often uses RGB or CMYK, and web, which usually uses hex.
  • Reconstructing a hex code from known RGB values when you're not sure you got it right.
  • Understanding how RGB and hex relate to each other.

Good to know

  • Values outside 0 to 255 get clamped automatically, so 300 becomes 255.
  • Non-whole numbers get rounded, since both formats only represent whole number intensities.
  • Keep an eye on the swatch. It's the fastest way to sanity check a conversion.
  • When sampling a color from a photo with an eyedropper, note the RGB values right away, since this is the fastest way to turn that sample into a usable CSS hex code.
  • When working from a printed color swatch book, remember those are usually CMYK based, so an RGB value estimated from a photo of the swatch will only ever be approximate.

Questions

Why does a hex code have six characters?

Each pair of characters represents one of the three color channels, red, then green, then blue, in hexadecimal. Three channels times two characters each gives six.

Can I enter percentages instead of 0 to 255?

This tool expects the standard 0 to 255 scale. If you have percentages, multiply each by 2.55 first to get them into that range.

What happens if I enter a negative number?

It gets treated as zero, since a color channel can't go below that.

Do I need all three values to get a hex code?

Yes, a color is fully defined by its combination of red, green, and blue, so all three fields need a value for an accurate conversion.

Can this handle RGBA with transparency?

This handles the three color channels only. A standard six character hex code doesn't include transparency, which would need an eight character hex or an rgba value instead.

Is there ever more than one correct hex code for a given RGB value?

No, the conversion is one to one. A specific combination of red, green, and blue values always converts to exactly one hex code.