# 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)`.

## 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)

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:

```def hex_to_rgb(hex_color):
hex_color = hex_color.replace(" ", "").replace("#", "")
# 3-digits hex color
if len(hex_color) == 3:
r = hex_color[0] * 2
g = hex_color[1] * 2
b = hex_color[2] * 2
# 6-digits hex color
elif len(hex_color) == 6:
r = hex_color[0:2]
g = hex_color[2:4]
b = hex_color[4:6]
else:
return "length error"
# convert hex to decimal
r = int(r, 16)
g = int(g, 16)
b = int(b, 16)
# check if in range 0~255
assert 0 <= r <= 255
assert 0 <= g <= 255
assert 0 <= b <= 255
# write rgb in correct syntax
rgb_color = "rgb({0},{1},{2})".format(r, g, b)
return rgb_color

hex_input = '#106ebe'
RGB_output = hex_to_rgb(hex_input)
print('RGB result is:{0}'.format(RGB_output))

-------------------
RGB result is:rgb(16,110,190)```