Generates a random color in CSS hex format
Generates a random color in CSS hex format.
npm install --save @chriscodesthings/random-css-hex-color
import randomCSSHexColor from '@chriscodesthings/random-css-hex-color';
console.log(randomCSSHexColor());
// => #c7a34b
randomCSSHexColor(tone);
- tone (optional): If true, colour is dark, if false, colour is light, based on YIQ calculation.
Returns a CSS hex color code string.
// pick a page background colour on page load
window.addEventListener("load", () => {
// light colour background should look ok with black text
document.body.style.background = randomCSSHexColor(false);
});
- random-rgb-color: Generates a random color in RGB format
- rgb-color-is-dark: Determine if a color in RGB format is dark using YIQ calculation
- is-css-hex-color: Determine if a string is a hex color code
- color-object: Simple, lightweight class to store and manipulate a color, and convert between formats