Skip to content

Determine if the given hex color is light or dark. Helpful to determining foreground color against a background color.

License

Notifications You must be signed in to change notification settings

ForkLibrary/contrast

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

contrast

Determine if the given color is light or dark.

This is useful for dynamically deciding which color a foreground color should be when placed over a given background color.

Install

npm install contrast --save

Usage

var contrast = require('contrast');

var el = document.querySelector('#some-element');
var bgColor = e.style.backgroundColor;

if (contrast(bgColor) === 'light') {
  textColor = '#000';
}
else {
  textColor = '#fff'
}

el.style.color = textColor;

Run Tests

npm install
npm test

About

Determine if the given hex color is light or dark. Helpful to determining foreground color against a background color.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • JavaScript 100.0%