Generate a random hex color code in JavaScript
Learn how to generate a random hexadecimal color code with a few lines of JavaScript.
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.
Learn how to generate a random hexadecimal color code with a few lines of JavaScript.
Learn how to easily convert between the various color formats, using JavaScript and a few simple formulas.
Learn how to convert a 3-digit RGB notated hexadecimal color-code to the 6-digit form.
Learn how to change the lightness component of an hsl()
color string using JavaScript.
Easily convert an rgb()
color string to an array of values or an object with the values of each color.
Easily convert an hsl()
color string to an array of values or an object with the values of each color.