getContrast
Commons
stable
Computes the WCAG 2 contrast ratio between two colors. A ratio of 4.5 meets AA for normal text; 3.0 meets AA for large text.
API
Signature
Full TypeScript signature sourced from the util file.
API
Parameters
Input parameters accepted by this util.
- firstrequiredTColorType
- The first color — any format accepted by parseColor (#hex, rgb(), hsl(), number, RGBA/HSLA object).
- secondrequiredTColorType
- The second color — same formats as first.
API
Return value
The value returned by this util.
- The WCAG 2 contrast ratio (1–21). Higher is better; 4.5 = AA for normal text, 7 = AAA.
Usage
Examples
Ready-to-paste usage snippets.
Check contrast between two colors