Function Repository Resource:

# HexToColor

Convert hex strings into colors

Contributed by: Michael Sollami
 ResourceFunction["HexToColor"][hex] converts a string hex into an equivalent color. ResourceFunction["HexToColor"][hex,form] converts a string hex into a color specified by form.

## Details and Options

The first argument hex should be a string of the format "#XXXXXX" (where each X is a digit or a letter in the range of "a" to "f").
The first argument hex may also be given in the following formats:
 "#RRGGBBAA" eight-digit hexadecimal "#RRGGBB" six-digit hexadecimal "#RGB" three-digit hexadecimal form "#RRGG" no blue channel "#RR" only red channel
In the single argument case, the form defaults to "RGB" and an RGBColor[] is returned.
Allowed values for form include:
 "RGB" | "RGBA" RGBColor value with optional alpha "Real" List of real channel values in the interval [0,1] "Integer" List of integer channel values in the set {0,…,255}
ResourceFunction["HexToColor"] ignores capitalization and works on strings with or without a prefixed octothorpe.
ResourceFunction["HexToColor"] is Listable.

## Examples

### Basic Examples (5)

Convert hex strings into colors:

 In[1]:=
 Out[1]=

Convert hex strings with alpha:

 In[2]:=
 Out[2]=

Convert hex strings directly to integer lists:

 In[3]:=
 Out[3]=

Create a basic RGB color table:

 In[4]:=
 Out[4]=

HexToColor is effectively the inverse of the resource function ColorToHex:

 In[5]:=
 Out[5]=

### Properties and Relations (2)

The system symbol RGBColor works for some cases out of the box:

 In[6]:=
 In[7]:=
 Out[7]=

However, HexToColor offers many additional conveniences, as well as support for alpha:

 In[8]:=
 Out[8]=

Michael Sollami

## Version History

• 1.0.0 – 11 December 2020