Hex to RGB Converter Online Tool

Hex Color#

RGB Color

About Hex to RGB Converter Online Tool:

This online Hex to RGB converter tool helps you to convert one Hex color (base 16) into a RGB color (base 10), and test the result color within the website.

Hex Color System:

the Color System used in HTML is also be written down as Hex number, from #000000 (pure black) to #FFFFFF (pure white). For example, #123456 means the Red is "12" (in range "00" to "FF"), the Green is "34", the Blue is "56". The Hex color system also support 3-digits color, for example, color #e1a is equivalent to #ee11aa.

RGB Color System:

The RGB color ("R" stands for "Red", "G" stands for "Green", "B" stands for "Blue") is specified how much red, green and blue light are combined together. The syntax is rgb(16,110,190).

comic hex to rgb

How to convert from Hex to RGB?

  1. Step 1: Get the hex number of each sub-color (Red, Green and Blue).

  2. Step 2: Convert each hex number into decimal number.

  3. Step 3: Write the RGB Color result String in correct syntax.

Example 1: Convert Hex Color "#106ebe" to RGB Color (result is "rgb(16,110,190)"):

Step 1: Hex Color "#106ebe": Red(0x10), Green(0x6e), Blue(0xbe)
Step 2: Red: (0x10)->(16), Green: (0x6e)->(110), Blue: (0xbe)->(190)
Step 3: Hex Color "#106ebe" -> rgb(16,110,190)

Example 2: Convert Hex Color "#ea3" to RGB Color (result is "rgb(238,170,51)"):

Step 1: Hex Color "#ea3" -> "#eeaa33"
Step 2: Hex Color "#eeaa33": Red(0xee), Green(0xaa), Blue(0x33)
Step 3: Red: (0xee)->(238), Green: (0xaa)->(170), Blue: (0x33)->(51)
Step 4: Hex Color "#ea3" -> rgb(238,170,51)

More information:

Wikipedia (Web colors): https://en.wikipedia.org/wiki/Web_colors

Wikipedia (RGB color model): https://en.wikipedia.org/wiki/RGB_color_model

Convert Hex to RGB with Python:

  1. def hex_to_rgb(hex_color):
  2. hex_color = hex_color.replace(" ", "").replace("#", "")
  3. # 3-digits hex color
  4. if len(hex_color) == 3:
  5. r = hex_color[0] * 2
  6. g = hex_color[1] * 2
  7. b = hex_color[2] * 2
  8. # 6-digits hex color
  9. elif len(hex_color) == 6:
  10. r = hex_color[0:2]
  11. g = hex_color[2:4]
  12. b = hex_color[4:6]
  13. else:
  14. return "length error"
  15. # convert hex to decimal
  16. r = int(r, 16)
  17. g = int(g, 16)
  18. b = int(b, 16)
  19. # check if in range 0~255
  20. assert 0 <= r <= 255
  21. assert 0 <= g <= 255
  22. assert 0 <= b <= 255
  23. # write rgb in correct syntax
  24. rgb_color = "rgb({0},{1},{2})".format(r, g, b)
  25. return rgb_color
  26.  
  27.  
  28. hex_input = '#106ebe'
  29. RGB_output = hex_to_rgb(hex_input)
  30. print('RGB result is:{0}'.format(RGB_output))
  31.  
  32. -------------------
  33. RGB result is:rgb(16,110,190)