Package Exports
- @chriscodesthings/random-css-hex-color
- @chriscodesthings/random-css-hex-color/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@chriscodesthings/random-css-hex-color) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
random-css-hex-color

Generates a random color in CSS hex format
Description
Generates a random color in CSS hex format.
See...
Install
npm install --save @chriscodesthings/random-css-hex-color
Use
import randomCSSHexColor from '@chriscodesthings/random-css-hex-color';
console.log(randomCSSHexColor());
// => #c7a34b
Syntax
randomCSSHexColor(tone);
Parameters
- tone (optional): If true, colour is dark, if false, colour is light, based on YIQ calculation.
Return Value
Returns a CSS hex color code string.
Examples
// 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);
});
See Also...
- 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