Skip to content

Instantly share code, notes, and snippets.

@lvnam96
Created September 4, 2017 06:27
Show Gist options
  • Save lvnam96/d341d3885244c285efc7590b7d9c107b to your computer and use it in GitHub Desktop.
Save lvnam96/d341d3885244c285efc7590b7d9c107b to your computer and use it in GitHub Desktop.
Generate random dark HSL color (CSS) in JavaScript
const getRandomColor = () => {
const h = Math.floor(Math.random() * 360),
s = Math.floor(Math.random() * 100) + '%',
l = Math.floor(Math.random() * 60) + '%';// max value of l is 100, but I set to 60 cause I want to generate dark colors
// (use for background with white/light font color)
return `hsl(${h},${s},${l})`;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment