Skip to content

Calculate a WCAG contrast ratio based on a foreground and background color

Notifications You must be signed in to change notification settings

vutran/contrast-ratio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

contrast-ratio

Calculate a WCAG contrast ratio based on a foreground and background color

Note: This module only accepts rgb values for simplicity. If you're trying to obtain a ratio for hex, consider using a helper function/module to first convert your hex strings to an rgb tuple.

Install

$ npm i -S contrast-ratio

Usage

const ratio = require("contrast-ratio");

ratio([255, 255, 255], [0, 0, 0]);
// -> 21

ratio([0, 0, 255], [255, 255, 255]);
// -> 8.59

License

MIT © Vu Tran

About

Calculate a WCAG contrast ratio based on a foreground and background color

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published