Skip to main content
Module

x/a11y_color_contrast/mod.ts>wcagContrastValue

A TypeScript package to calculate WCAG 2.0/3.0 and APCA color contrasts
Latest
function wcagContrastValue
import { wcagContrastValue } from "https://deno.land/x/a11y_color_contrast@v0.2.0/mod.ts";

This function calculates the contrast value between two colors based on WCAG contrast readability criteria. The first color is the foreground color and the second the background color (defaulting to pure white, "#fff" / [255, 255, 255]).

import { wcagContrastValue } from "./wcag.ts";

wcagContrastValue([0, 255, 0], [0, 0, 0]) // green on black
// 15.303999999999998

wcagContrastValue([169, 169, 169], [0, 0, 0]) // dark gray on black
// 2.6043964062893665

See https://www.w3.org/WAI/WCAG22/Techniques/general/G17.html for concrete details for WCAG 2.2.

Parameters

foreground: Color
optional
background: Color = [UNSUPPORTED]

Returns

number