contrast_ratio
The WCAG contrast ratio between two colors, from 1.0 (identical) to 21.0 (black on white).
It is (L1 + 0.05) / (L2 + 0.05) where L1 is the relative luminance of the lighter color
and L2 of the darker one, so the order of the arguments does not matter. WCAG 2.x asks for
at least 4.5 for normal text and 3.0 for large text (level AA), 7.0 and 4.5 for AAA.
Import
Section titled “Import”Cargo feature color (enabled by default). To compile only this module:
or in Cargo.toml:
Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
a | Rgb | One color, for instance the text. |
b | Rgb | The other color, for instance its background. |
Returns
Section titled “Returns”f64 — The ratio, 1.0..=21.0.
