Creating HTML Colors

by Nov 19, 2014

All Versions

To convert decimal color values to a hexadecimal representation, like the one used in HTML, try this line:

 
PS> '#{0:x2}{1:x2}{2:x2}{3:x2}' -f 255,202,81,0
#ffca5100

PS> '#{0:x2}{1:x2}{2:x2}{3:x2}' -f 255,0,121,204
#ff0079cc 

The first value sets the transparency, followed by the byte values for red, green, and blue.

Twitter This Tip! ReTweet this Tip!