in Javascript

How To Make Random Hex Colour In Javascript

Color 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. Demo

Subscribe To The Weekly Newsletter

Get weekly updates to your email