@chriscodesthings/random-css-hex-color
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

random-css-hex-color
Test workflow status NPM Version License: MIT

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...

Readme

Keywords

Package Sidebar

Install

npm i @chriscodesthings/random-css-hex-color

Weekly Downloads

2

Version

1.1.0

License

MIT

Unpacked Size

7.32 kB

Total Files

8

Last publish

Collaborators

  • chriscodesthings