contrast_ratio()
Compute the APCA contrast ratio between two colors.
Usage
contrast_ratio(
bg_color,
fg_color,
)Parameters
bg_color: str-
Background color as a hex string (e.g.,
"#2c3e50"). fg_color: str-
Foreground (text) color as a hex string.
Returns
float-
The APCA Lc contrast value. Higher absolute values indicate stronger contrast.
Examples
>>> contrast_ratio("#000000", "#FFFFFF")
106.04
>>> contrast_ratio("#FFFFFF", "#000000")
-107.88