DEV Community

loading...

Discussion on: Generate and Set Pseudorandom Hexadecimal Background Color Using JavaScript

Collapse
webreflection profile image
Andrea Giammarchi • Edited
function generateRandomHexColor() {
  const rgb = () => ('0' + (Math.random() * 256).toString(16)).slice(-2);
  return `#${rgb()}${rgb()}${rgb()}`;
}