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

Upgrade to access all content on Paulund

Members unlock all tutorials and snippets

Access to all downloadable content

Access to code examples before others

Sign Up Now

Already a member? Login here

Subscribe To The Weekly Newsletter

Get weekly updates to your email