DEV Community

Discussion on: JS: How to implement a Random Background Color Change to make your sites more professional

Collapse
 
jackherizsmith profile image
Jack • Edited

Fun! It's also worth promoting HSL, which is a more intuitive way of reading colour in code. Something like

const getRandom = n => Math.random() * n;

function random_bg_color() {
  const h = getRandom(360);
  const s = getRandom(100);
  const l = getRandom(100);
  // ... etc
}
Enter fullscreen mode Exit fullscreen mode

HSL is great because if you see for example 120, 50%, 70% you know you're going to see a pale pastel green, which isn't as obvious with hex/RGB (140, 217, 140).