Skip to main content

apca_contrast

Function apca_contrast 

Source
pub fn apca_contrast(text_color: Hsla, background_color: Hsla) -> f32
Expand description

Calculates the perceptual lightness contrast using APCA. Returns a value between approximately -108 and 106. Negative values indicate light text on dark background. Positive values indicate dark text on light background.

The APCA algorithm is more perceptually accurate than WCAG 2.x, especially for dark mode interfaces. Key improvements include:

  • Better accuracy for dark backgrounds
  • Polarity-aware (direction matters)
  • Perceptually uniform across the range

Common APCA Lc thresholds per ARC Bronze Simple Mode: https://readtech.org/ARC/tests/bronze-simple-mode/

  • Lc 45: Minimum for large fluent text (36px+)
  • Lc 60: Minimum for other content text
  • Lc 75: Minimum for body text
  • Lc 90: Preferred for body text

Most terminal themes use colors with APCA values of 40-70.

https://github.com/Myndex/apca-w3