Functions
contrast_ratio
2
float
▼
Compute WCAG 2.0 contrast ratio between foreground and background.
contrast_ratio
2
float
▼
def contrast_ratio(fg: str, bg: str) -> float
Parameters
| Name | Type | Description |
|---|---|---|
fg |
str |
Foreground hex color (e.g. "#ffffff") |
bg |
str |
Background hex color (e.g. "#000000") |
Returns
float
passes_aa
2
bool
▼
Check if contrast ratio passes WCAG AA.
passes_aa
2
bool
▼
def passes_aa(ratio: float, *, large_text: bool = False) -> bool
Parameters
| Name | Type | Description |
|---|---|---|
ratio |
float |
Contrast ratio from contrast_ratio() |
large_text |
bool |
If True, use 3:1 threshold; else 4.5:1. Default:False
|
Returns
bool
passes_aaa
2
bool
▼
Check if contrast ratio passes WCAG AAA.
passes_aaa
2
bool
▼
def passes_aaa(ratio: float, *, large_text: bool = False) -> bool
Parameters
| Name | Type | Description |
|---|---|---|
ratio |
float |
Contrast ratio from contrast_ratio() |
large_text |
bool |
If True, use 4.5:1 threshold; else 7:1. Default:False
|
Returns
bool