# contrast

> Determine if the given color is light or dark

Latest version **1.0.1** (published 2014-12-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install contrast
pnpm add contrast
yarn add contrast
bun add contrast
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2014-12-01 |
| First published | 2014-12-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 57 |
| Author | Scott Corgan |
| Maintainers | scottcorgan |
| Keywords | background, light, dark, color, hex, rgb |

## Links

- npm: https://www.npmjs.com/package/contrast
- Repository: https://github.com/scottcorgan/contrast
- Issues: https://github.com/scottcorgan/contrast/issues
- npm.io page: https://npm.io/package/contrast

## Dependencies (1)

- [hex-to-rgb](https://npm.io/package/hex-to-rgb.md) ^1.0.0

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2014-12-01
- 1.0.0 — 2014-12-01

## README

# 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

```js
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
```

---
_Source: https://npm.io/package/contrast · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
