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

Gain access to all tutorials

  • Premium tutorials covering WordPress, Laravel and VueJS
  • Download premium content
  • Download premium WordPress plugins
  • Only $5 a month

Join Paulund