About this endpoint
What it does
Checks the contrast between a foreground color and a background color, using the two input color values you provide. It returns the normalized colors, luminance values, contrast ratio, WCAG pass/fail flags, an overall level, and a recommendation string.
Request Body
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| fg | String | Yes | Foreground / text color. Accepts hex, rgb(), or a CSS color name. |
| bg | String | Yes | Background color. Accepts hex, rgb(), or a CSS color name. |
Response
Returns a JSON object with bg and fg string fields, a passes object, bg_luminance and fg_luminance number fields, overall_level and recommendation string fields, and a contrast_ratio number plus contrast_ratio_display string. The response is the computed color-contrast result for the submitted foreground/background pair.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| bg | String | No | Background color returned by the service. |
| fg | String | No | Foreground color returned by the service. |
| passes | Object | No | WCAG pass/fail results for text sizes and levels. |
| passes.AA_large_text | Boolean | No | true if the pair passes AA for large text, otherwise false. |
| passes.AAA_large_text | Boolean | No | true if the pair passes AAA for large text, otherwise false. |
| passes.AA_normal_text | Boolean | No | true if the pair passes AA for normal text, otherwise false. |
| passes.AAA_normal_text | Boolean | No | true if the pair passes AAA for normal text, otherwise false. |
| bg_luminance | Number | No | Luminance value for the background color. |
| fg_luminance | Number | No | Luminance value for the foreground color. |
| overall_level | String | No | Overall contrast level returned by the service. |
| contrast_ratio | Number | No | Calculated contrast ratio for the color pair. |
| recommendation | String | No | Recommendation returned by the service. |
| contrast_ratio_display | String | No | Display-formatted contrast ratio. |