# wcag-contrast

> evaluate the wcag color contrast score for two colors

Latest version **3.0.0** (published 2019-11-05) · BSD-2-Clause license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2019-11-05 |
| First published | 2013-09-24 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | separate (@types/wcag-contrast) |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 130 |
| Author | Tom MacWright |
| Maintainers | tmcw |
| Keywords | color, contrast, wcag |

## Links

- npm: https://www.npmjs.com/package/wcag-contrast
- Repository: https://github.com/tmcw/wcag-contrast
- Homepage: https://github.com/tmcw/wcag-contrast#readme
- Issues: https://github.com/tmcw/wcag-contrast/issues
- npm.io page: https://npm.io/package/wcag-contrast

## Dependencies (1)

- [relative-luminance](https://npm.io/package/relative-luminance.md) ^2.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

- 3.0.0 (latest) — 2019-11-05
- 2.1.2-0 (prerelease) — 2018-09-24
- 2.1.1 — 2018-09-24
- 2.1.0 — 2018-08-20
- 2.0.0 — 2018-08-20
- 1.2.0 — 2018-04-16
- 1.1.0 — 2018-03-21
- 1.0.0 — 2018-03-21
- 0.1.2-0 — 2018-03-21
- 0.1.1 — 2018-01-10
- 0.1.0 — 2015-09-18
- 0.0.0 — 2013-09-24

## README

## wcag color contrast

[![CircleCI](https://circleci.com/gh/tmcw/wcag-contrast.svg?style=svg)](https://circleci.com/gh/tmcw/wcag-contrast)

This module produces [WCAG](http://www.w3.org/WAI/intro/wcag.php) [contrast ratio](http://www.w3.org/TR/WCAG20/#contrast-ratiodef)
measurement and scoring. It's an accessibility standard, intended to make sure websites have high enough contrast to be readable by everyone, including people with [low vision](https://www.aao.org/eye-health/diseases/low-vision) and age-related vision problems. This module is a low-level utility, useful for its implementation of the underlying math: to test a page, you'll want to use something like Google Chrome’s [Lighthouse tools](https://developers.google.com/web/tools/lighthouse/), or the [axe extension](https://www.deque.com/axe/) for Chrome and Firefox.

I (personally, speaking as Tom) have doubts about the [universality, accuracy, and application of this particular standard](https://macwright.org/2019/03/30/color-contrast-is-a-problem.html). High contrast is a good value, but I argue that the standard is over-strict and doesn't precisely match human perception.

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### luminance

Get the contrast ratio between two relative luminance values

**Parameters**

-   `a` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** luminance value
-   `b` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** luminance value

**Examples**

```javascript
luminance(1, 1); // = 1
```

Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** contrast ratio

### rgb

Get a score for the contrast between two colors as rgb triplets

**Parameters**

-   `a` **[array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** 
-   `b` **[array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** 

**Examples**

```javascript
rgb([0, 0, 0], [255, 255, 255]); // = 21
```

Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** contrast ratio

### hex

Get a score for the contrast between two colors as hex strings

**Parameters**

-   `a` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** hex value
-   `b` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** hex value

**Examples**

```javascript
hex('#000', '#fff'); // = 21
```

Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** contrast ratio

### score

Get a textual score from a numeric contrast value

**Parameters**

-   `contrast` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** 

**Examples**

```javascript
score(10); // = 'AAA'
```

Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** score

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