Skip to content

Instantly share code, notes, and snippets.

@karenying
Created November 7, 2020 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karenying/2cdc07545ecda1e2919ff2a2157afdc2 to your computer and use it in GitHub Desktop.
Save karenying/2cdc07545ecda1e2919ff2a2157afdc2 to your computer and use it in GitHub Desktop.
// calculates contrast ratio between two hex strings
export function contrastRatioPair(hex1, hex2) {
const lum1 = getLuminance(hex1);
const lum2 = getLuminance(hex2);
return (Math.max(lum1, lum2) + 0.05) / (Math.min(lum1, lum2) + 0.05);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment