Skip to content
Calm motion: animations on this site only fade, with no movement

Contrast checker ​

Two colors in, the contrast ratio and the WCAG levels out

Tells a designer if a text color is easy to read on a background. It shows the ratio and which WCAG 2.1 levels pass. For the shades of a whole palette, use the palette viewer.

Basic
AaThe quick brown fox jumps over the lazy dog.

Contrast ratio5.16:1

  • AA, normal text: Pass
  • AA, large text: Pass
  • AAA, normal text: Fail
  • AAA, large text: Pass
  • Parts of the interface: Pass
  • v-model:text and v-model:background are the two colors, as hex. Each color has a native color input and a text field.
  • The ratio uses the relative luminance of WCAG 2.1, from 1:1 to 21:1. It is cut, not rounded, to two decimals, so a color that only just fails does not show as a pass.
  • The list shows the levels: AA needs 4.5:1 for normal text and 3:1 for large text, and AAA needs 7:1 and 4.5:1. Parts of the interface, such as the edge of a field, need 3:1.
  • Each level shows a mark and the word "Pass" or "Fail", so the result does not rest on the color. The ratio is a status line, so screen readers hear a change. The swap button changes the two colors over.
  • The functions behind it, contrastRatio and wcagLevels, come with the library.
  • Change the words with labels or a label pack: text, background, swap, ratio, sample, pass, fail, invalid, aaText, aaLarge, aaaText, aaaLarge, and ui.

Usage ​

ts
import { BlessContrastChecker, contrastRatio } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
labelsPartial<{ text: string; background: string; swap: string; ratio: string; sample: string; pass: string; fail: string; invalid: string; aaText: string; aaLarge: string; aaaText: string; aaaLarge: string; ui: string; }>—
textstring"#3f4245"
backgroundstring"#f4f4f5"

Events

NamePayloadDescription
update:text[value: string]
update:background[value: string]

Released under the MIT License. Character names and artwork belong to their owners.