Skip to main content

Generating Random Color Values using JavaScript

By Sam Deering
JavaScript
Share:

JavaScript Code snippet to generate a random RGB color. Could be useful for supplying color values to transitions to/from with a single line of code.


See Demo

var hue = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';

Tags

jQuery

Sam Deering has 15+ years of programming and website development experience. He was a website consultant at Console, ABC News, Flight Centre, Sapient Nitro, and the QLD Government and runs a tech blog with over 1 million views per month. Currently, Sam is the Founder of Crypto News, Australia.

Integromat Tower Ad