Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Convert hex strings into colors
| 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. | 
| "#RRGGBBAA" | eight-digit hexadecimal | 
| "#RRGGBB" | six-digit hexadecimal | 
| "#RGB" | three-digit hexadecimal form | 
| "#RRGG" | no blue channel | 
| "#RR" | only red channel | 
| "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} | 
Convert hex strings into colors:
| In[1]:= | ![ResourceFunction[
 "HexToColor"] /@ {"#f", "#0f0", "#8080", "#a03393", "#a0339333"}](https://www.wolframcloud.com/obj/resourcesystem/images/a83/a83352ca-b04e-4173-b1cb-9b8900ce4c26/21043d4ab5715cd9.png) | 
| Out[1]= |  | 
Convert hex strings with alpha:
| In[2]:= | ![ResourceFunction["HexToColor"]["#22ffff44", #] & /@ {"RGBA", "Real"}](https://www.wolframcloud.com/obj/resourcesystem/images/a83/a83352ca-b04e-4173-b1cb-9b8900ce4c26/69a5d37af7fd9362.png) | 
| Out[2]= |  | 
Convert hex strings directly to integer lists:
| In[3]:= | ![# -> ResourceFunction["HexToColor"][ResourceFunction["ColorToHex"]@#, "Integer"] & /@ RandomColor[10] // Multicolumn](https://www.wolframcloud.com/obj/resourcesystem/images/a83/a83352ca-b04e-4173-b1cb-9b8900ce4c26/39f419d507152f50.png) | 
| Out[3]= |  | 
Create a basic RGB color table:
| In[4]:= | ![Dataset[{#, ResourceFunction["HexToColor"][#, "RGB"], ResourceFunction["HexToColor"][#, "Integer"]} & /@ {"#000000", "#C0C0C0", "#FFFFFF", "#FF0000", "#FFFF00", "#00FF00", "#00FFFF", "#0000FF", "#FF00FF"}]](https://www.wolframcloud.com/obj/resourcesystem/images/a83/a83352ca-b04e-4173-b1cb-9b8900ce4c26/2b0b21d212735271.png) | 
| Out[4]= |  | 
HexToColor is effectively the inverse of the resource function ColorToHex:
| In[5]:= | ![Row@{ColorSlider[Dynamic[c]], Spacer[10], Framed@Dynamic[
    Style[h = ResourceFunction["ColorToHex"]@c, FontFamily -> "Courier", FontSize -> 30, FontColor -> ResourceFunction["HexToColor"]@h]]}](https://www.wolframcloud.com/obj/resourcesystem/images/a83/a83352ca-b04e-4173-b1cb-9b8900ce4c26/0103206e2e38fa10.png) | 
| Out[5]= |  | 
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]:= | ![ResourceFunction["HexToColor"]@tests](https://www.wolframcloud.com/obj/resourcesystem/images/a83/a83352ca-b04e-4173-b1cb-9b8900ce4c26/07c29070257966bf.png) | 
| Out[8]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License