Reload demos Made by David Merfield.

randomColor

A color generator for JavaScript.

Get the code on GitHub  →

Why does this exist?

There are lots of clever one-liners for generating random colors:

'#'+Math.floor(Math.random()*16777215).toString(16);

Unfortunately, this code naturally produces lots of greys and browns and murky greens.


randomColor generates attractive colors by default. More specifically, randomColor produces bright colors with a reasonably high saturation. This makes randomColor particularly useful for data visualizations and generative art.




Examples

Once you've included randomColor.js on your page, calling randomColor() will return a random attractive color. Beneath is the output of randomColor called 54 times.

randomColor(); // Returned a random color as a hex string


Extras

You can also pass an options object to randomColor. This allows you to specify the hue, luminosity and the number of colors to generate.


Similar colors

randomColor({hue: 'red', count: 18});
randomColor({hue: 'orange', count: 18});
randomColor({hue: 'yellow', count: 18});
randomColor({hue: 'green', count: 18});
randomColor({hue: 'blue', count: 18});
randomColor({hue: 'purple', count: 18});
randomColor({hue: 'pink', count: 18});
randomColor({hue: 'monochrome', count: 18});

Light colors

randomColor({luminosity: 'light',count: 27});

Dark colors

randomColor({luminosity: 'dark', count: 27});

Truly random colors

randomColor({hue: 'random',luminosity: 'random',count: 54});
Get this on Github  →