Widgets & Mini-Apps

Design system palette contrast matrices: Instant WCAG AA & AAA readability auditing

Designing accessible palettes shouldn't be an afterthought. I built this palette contrast auditor so you can test foreground text against background colors in real time, guaranteeing that every card meets strict WCAG AA rules.

Palette Contrast Checker Studio

Three Steps to Embed Live Accessibility Checkers

1

Select Color Pair

Pick your foreground text color and background surface color using hex codes or the interactive picker.

2

Inspect WCAG Matrix

Check real-time pass/fail ratings for Normal Text (4.5:1), Large Headings (3.0:1), and Enhanced AAA (7.0:1).

3

Export Zero-Dependency Code

Copy production CSS and vanilla JS with mathematical luminance calculation ready for design systems and styleguides.

Features & CSS Best Practices

✓

W3C WCAG 2.1 Formula

Accurate gamma expansion and sRGB relative luminance calculation conforming to official W3C accessibility specs.

✓

One-Click Color Swapper

Instant ⇄ swap button checks foreground and background inverted combinations with sub-millisecond recalculation.

✓

Live Text Sample Preview

Inspect typography legibility directly on the actual background surface before writing CSS styles.

✓

Zero External Dependencies

Skip heavy color manipulation libraries like Chroma.js; runs in pure native JavaScript under 2KB.

The Mathematical Foundation of Relative Luminance

Human eyes perceive green wavelengths much brighter than blue wavelengths. Simple RGB distance averages fail to measure true visual contrast. The W3C specification defines relative luminance by first linearizing gamma values and applying spectral weighting:

function luminance(r, g, b) {
  const [rs, gs, bs] = [r, g, b].map(c => {
    c = c / 255;
    return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
  });
  return 0.2126 * rs + 0.7152 * gs + 0.0722 * bs;
}

Calculating Contrast Ratios

Contrast ratio is given by:

\[\text{CR} = \frac{L_1 + 0.05}{L_2 + 0.05}\]

where \(L_1\) is the relative luminance of the lighter of the colors, and \(L_2\) is the relative luminance of the darker color. The ratio ranges from 1:1 (zero contrast) to 21:1 (pure black on pure white).

WordPress & Elementor Integration

How to Use This Contrast Checker in Elementor

Document accessibility compliance directly in your WordPress design system. Embed this live WCAG contrast scorecard card into your Elementor pages in 3 simple steps.

1

Copy Elementor / WP Code

In the code studio above, switch to the Elementor / WP tab and click Copy to get the self-contained bundle with scoped CSS, scorecard markup, and contrast math JS.

2

Insert an HTML Widget

In your WordPress dashboard, open your Elementor style guide, brand page, or template. Drag an HTML widget onto your canvas.

3

Paste & Publish

Paste the snippet into the HTML Code box. The contrast card renders immediately with live contrast ratio calculations, AA/AAA compliance badges, and color swapping.

🎨

Sync with Elementor Global Colors

Easily test your site palette by linking --cc-fg and --cc-bg in the <style> block to var(--e-global-color-text) and var(--e-global-color-primary).

⚡

WCAG 2.1 Formula Accuracy

Applies exact relative luminance formulas with sRGB gamma expansion, delivering mathematically certified contrast ratios for accessibility audits.

Frequently Asked Questions

How is the WCAG 2.1 contrast ratio calculated?

The widget applies the W3C WCAG 2.1 relative luminance formula: L = 0.2126*R + 0.7152*G + 0.0722*B (sRGB values gamma-expanded). The contrast ratio is defined as (L1 + 0.05) / (L2 + 0.05), where L1 is the lighter color.

What are the minimum contrast requirements for AA and AAA compliance?

WCAG 2.1 Level AA requires a minimum ratio of 4.5:1 for regular text and 3:1 for large text (18pt or 14pt bold). Level AAA requires 7:1 for regular text and 4.5:1 for large text.

Can this badge be embedded into design token documentation?

Yes. The generated code is self-contained with pure CSS and vanilla JS, making it perfect for embedding into design systems, component styleguides, or live docs.

How do I embed this WCAG contrast checker card in Elementor?

Switch to the Elementor / WP tab in the code studio above and click Copy. In WordPress, open your Elementor page or design system guide, drag an HTML widget onto your canvas, and paste the code snippet. The contrast card renders immediately with real-time luminance math, AA/AAA compliance badges, and interactive color swapping without external dependencies.