Skip to main content
Generates accessible color combinations that meet WCAG contrast requirements.

Usage

Parameters

Return Value

Contrast Requirements

The hook ensures colors meet WCAG accessibility standards:
  • Text (foreground): 4.5:1 contrast ratio against background
  • Border: 3:1 contrast ratio against page background
  • Colors are iteratively adjusted up to 16 times to meet requirements

Examples

Dynamic Badge Colors

Theme-Aware Colors

User-Selected Colors

Algorithm Details

Light Mode

  1. Determines if the background is light or dark using contrast comparison
  2. Selects white or dark text based on background
  3. Ensures 4.5:1 contrast ratio for text readability
  4. Falls back to black text if contrast is insufficient
  5. Generates border color with 3:1 contrast against page background

Dark Mode

  1. Starts with the provided color for both foreground and background
  2. Ensures background meets darkness threshold for dark themes
  3. Iteratively adjusts foreground and background for 4.5:1 contrast
  4. Prioritizes background darkening to maintain theme consistency
  5. Generates border color with 3:1 contrast against page background
Last modified on December 22, 2025