How do I randomly generate HTML hex color codes using JavaScript? [duplicate]

This will generate a random number within the bounds and convert it to hexadecimal. It is then padded with zeros so that it’s always a valid six-digit hex code.

'#'+(Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0');

Leave a Comment