Hex to RGBA Converter Online Tool

Hex Color#

Opacity%

RGBA Color

About Hex to RGBA Converter Online Tool:

This online Hex to RGBA converter tool helps you to convert one Hex color (base 16) into a RGBA color (base 10, with Opacity), 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.

RGBA Color System:

The RGBA 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, and what the overall opacity. The syntax is rgba(16,110,190,0.7).

comic hex to rgba

How to convert from Hex to RGBA?

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

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

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

Example 1: Convert Hex Color "#106ebe" (with opacity 80%) to RGBA Color (result is "rgba(16,110,190,0.8)"):

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" opacity 80% -> rgba(16,110,190,0.8)

Example 2: Convert Hex Color "#ea3" (with opacity 100%) to RGB Color (result is "rgba(238,170,51,1)"):

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", opacity 100% -> rgba(238,170,51,1)

More information:

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

Wikipedia (RGBA color space): https://en.wikipedia.org/wiki/RGBA_color_space

Convert Hex to RGBA with Python:

import re


def rgba_to_hex(rgba_color):
    rgb_color = re.search('\(.*\)', rgba_color).group(0).replace(' ', '').lstrip('(').rstrip(')')
    [r, g, b, o] = rgb_color.split(',')
    [r, g, b] = [int(x) for x in [r, g, b]]
    o = float(o) * 100
    o = str(o) + '%'

    # check if in range 0~255
    assert 0 <= r <= 255
    assert 0 <= g <= 255
    assert 0 <= b <= 255

    r = hex(r).lstrip('0x')
    g = hex(g).lstrip('0x')
    b = hex(b).lstrip('0x')
    # re-write '7' to '07'
    r = (2 - len(r)) * '0' + r
    g = (2 - len(g)) * '0' + g
    b = (2 - len(b)) * '0' + b

    hex_color = '#' + r + g + b + ', with opacity:' + o
    return hex_color


rgba_input = 'rgba(7,110,190,0.95)'
hex_output = rgba_to_hex(rgba_input)
print('Hex color result is:{0}'.format(hex_output))

-------------------
Hex color result is:#076ebe, with opacity:95.0%