About this endpoint
What it does
Checks whether two colors have enough contrast to be readable, using the WCAG accessibility guidelines. Send a foreground (text) color and a background color as hex codes, and get back the contrast ratio from 1 to 21 and whether it passes WCAG AA, AAA and AA for large text. Use it in design tools, theme builders and accessibility audits.
Request Body
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| foreground | String | Yes | Foreground color as a hex code, e.g. #000 or #000000. rgb() and color names are not supported. |
| background | String | Yes | Background color as a hex code, e.g. #fff or #ffffff. rgb() and color names are not supported. |
Response
A successful call returns a JSON object with these fields:
| Parameter | Type | Description |
|---|---|---|
| tool | String | Name of the tool that produced the response. |
| ratio | Number | Contrast ratio between the two colors, from 1 to 21. |
| aa | Boolean | true if the ratio meets WCAG AA for normal text (4.5 or higher). |
| aaa | Boolean | true if the ratio meets WCAG AAA for normal text (7 or higher). |
| aaLarge | Boolean | true if the ratio meets WCAG AA for large text (3 or higher). |
| error | String | Error message. Present only when the input is invalid, e.g. "Invalid hex color". |
If a color is not a valid hex code, the API returns {"error":"Invalid hex color"}.



