AccessibilityBy PaletteKey Team 7 min read

How to Choose Accessible Text and Background Colors

A step-by-step workflow for pairing UI foregrounds and backgrounds compliant with WCAG.

Key Technical Takeaway

Creating accessible color combinations requires a structured design workflow. Learn how to pair foreground text with background surfaces, adjust lightness in OKLCH space, and maintain contrast across light and dark themes.

Step-by-Step Accessible Pairing Workflow

To ensure every text element meets WCAG 2.2 AA standards without guessing, follow this 7-step engineering workflow:

  • Step 1: Define the base surface/container background color (e.g., #F8FAFC in light mode, #0F172A in dark mode).
  • Step 2: Choose a candidate foreground text color.
  • Step 3: Measure the contrast ratio using relative luminance calculation.
  • Step 4: Check against target criteria (4.5:1 for body text, 3.0:1 for headings/icons).
  • Step 5: If contrast fails, adjust Lightness in OKLCH space (lower L for dark text, raise L for light text).
  • Step 6: Test interactive hover, active, and focus states against the same surface.
  • Step 7: Re-evaluate state badges (error, success, warning) to ensure color is accompanied by text or icons.

Why Visually Similar Colors Have Different Contrast

Because human vision perceives green light as vastly brighter than blue, two colors with identical saturation and lightness in HSL can produce dramatically different contrast ratios when paired with white or black backgrounds.

/* HSL Blue vs HSL Green on White Background (#FFFFFF) */
--blue-text:  hsl(220 90% 50%); /* Contrast against white: 4.8:1 (PASS AA) */
--green-text: hsl(120 90% 50%); /* Contrast against white: 1.4:1 (FAIL AA) */

/* Adjusting Green in OKLCH to Pass 4.5:1 Contrast */
--accessible-green: oklch(0.42 0.18 142); /* Contrast against white: 4.6:1 (PASS AA) */

Never Rely on Color Alone for Meaning

WCAG 2.2 Success Criterion 1.4.1 mandates that color must not be the sole visual means of conveying information, indicating an action, or distinguishing an element. Always pair state colors with text labels, icons, or underline indicators.

<!-- BAD: Color alone signals error -->
<input class="border-red-500" value="Invalid email" />

<!-- GOOD: Color + Alert Icon + Text Message -->
<div class="flex items-center gap-2 text-red-600">
  <ErrorIcon aria-hidden="true" />
  <span>Please enter a valid email address.</span>
</div>

Put Theory into Practice with Free Color Tools

Apply the concepts from this guide directly in your web workflow with our interactive tools.