MI
misund/get-best-contrast-color
Calculate wich color in a array of colors gives the highest contrast to another color.
Get best contrast color
get-best-contrast-color calculates which color in an array of colors gives the highest contrast to another color.
Doesn't handle transparency as of yet.
Installation
$ npm install get-best-contrast-colorUsage
import bestContrast from 'get-best-contrast-color';
const background1 = 'palevioletred';
const background2 = 'saddlebrown';
const colors = [
'#222',
'blue',
'rgb(255, 255, ,255)',
];
bestContrast(background1, colors); // '#222'
bestContrast(background2, colors); // 'rgb(255, 255, 255)'Signature
(background: string, colors: array) => string
Contributing
I appreciate your issues and PRs on Github!
Testing
yarn build && yarn test
Releasing
This project uses np.
- Make sure your changes are on main
- Run
yarn release - Follow the interactive release guide
On this page
Languages
TypeScript74.4%JavaScript25.6%
Created May 20, 2018
Updated October 13, 2025