Working with color in JavaScript requires some understanding of color formats and conversions. This snippet collection covers a lot of those needs from generating random color hex codes to converting between hex and RGB values and even some more advanced tricks like using the HSL format to alter the lightness of a color.
Converts the values of RGB components to a hexadecimal color code.
JavaScript, String · Nov 3, 2020
Extends a 3-digit color code to a 6-digit color code.
JavaScript, String · Sep 15, 2020
Converts a color code to an rgb()
or rgba()
string if alpha value is provided.
JavaScript, String · Oct 19, 2020
Converts an rgb()
color string to an object with the values of each color.
JavaScript, String · Oct 22, 2020
Changes the lightness value of an hsl()
color string.
JavaScript, String · Oct 31, 2020
Converts an hsl()
color string to an object with the values of each color.
JavaScript, String · Oct 22, 2020