How To Make Random Hex Colour In Javascript


In this tutorial you will learn how to create random colours using Javascript.

To create a random colour in Javascript it is a simple function.

function random_colour(){
     return Math.floor(Math.random()*16777215).toString(16);

View the demo to see how this can be used to change the background colour of the page.

Just click the random button and the Javascript will create a new random colour and set this as the background.


Back to top

Fastest WordPress Hosting With WPEngine

Stunning speed, powerful security, and best-in-class customer service. At WP Engine.

Risk free for 60 days