Generate random hex code

Published on August 12th, 2019

hash icon

This will be short and not really practical but fun article.

Have you ever wondered how to generate random hex code?

Probably not, but here it is.

'#' + Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, '0');

One-liner, short and sweet.

Now you can use it to create fun web pages like demo I’ve created for this article.