gui.palette.contrast_ratio

gui.palette.contrast_ratio(foreground, background)

The WCAG contrast ratio of two #RRGGBB colours.

Parameters

Name Type Description Default
foreground str Hex colour of the text. required
background str Hex colour of the background. required

Returns

Name Type Description
float float A ratio from 1 (identical) to 21 (black on white).

Examples

from spotregen.gui.palette import contrast_ratio

print(round(contrast_ratio("#000000", "#FFFFFF")))
21