RGB to Hex Converter

RGB

Hex


RGB to Hex Conversion

RGB (specifically RGB255) uses decimal values from 0-255 for each color channel, while hexadecimal colors use base-16 notation with values from 00 to FF for each channel. They both represent the same range of colors, just in different formats.

For example, the RGB color rgb(255, 0, 0) (pure red) converts to the hex color #ff0000.

Algorithm to convert RGB to Hex

To convert RGB to hex, each RGB component is converted from base-10 (decimal) to base-16 (hexadecimal):

  1. Take the red value (0-255) and convert it to hexadecimal (00-FF).
  2. Take the green value (0-255) and convert it to hexadecimal (00-FF).
  3. Take the blue value (0-255) and convert it to hexadecimal (00-FF).
  4. Combine them with a # prefix: #RRGGBB

For RGBA colors with transparency, the alpha channel is also converted and appended: #RRGGBBAA. The alpha value is converted from the 0-1 decimal range to 0-255, then to hexadecimal.

Common RGB to Hex conversions

Here are some frequently used color conversions:

  • rgb(255, 255, 255)#ffffff (white)
  • rgb(0, 0, 0)#000000 (black)
  • rgb(255, 0, 0)#ff0000 (red)
  • rgb(0, 255, 0)#00ff00 (green)
  • rgb(0, 0, 255)#0000ff (blue)
  • rgb(128, 128, 128)#808080 (gray)
Need to convert the other way? Use our Hex to RGB Converter to convert hexadecimal color codes back to RGB values.