
WCAG Text Contrast Checker API
Accessibility
Check colour contrast ratios to ensure accessibility compliance with WCAG guidelines (Level AA and AAA).
Authentication
All API requests require a valid API key passed in the Authorization header as a Bearer token.
Rate Limit
120 requests per minute
Endpoints
2 endpoints available
Overview
Check the contrast between a text colour and a background colour against WCAG AA and AAA, or against a minimum ratio of your own. Colours are hex values, 3 or 6 digits, with or without the leading #.
Thresholds
- AA: 4.5:1 for normal text, 3:1 for large text
- AAA: 7:1 for normal text, 4.5:1 for large text
- Text counts as large at a
fontSizeof 18 px or more. Bold text between 14 px and 18 px is not treated as large here.
Endpoints
POST /v1/tools/wcag-text-checkerchecks one pair.checkTypeiswcag(default) orcustom.POST /v1/tools/wcag-text-checker/batchchecks up to 100 pairs against AA and AAA.
Colours in responses are normalised to lowercase 6-digit hex. contrastRatio is rounded to two decimals.
Endpoints
POST
https://opentools.ca/api/v1/tools/wcag-text-checkerCheck the contrast of one colour pair
Request Body
Content-Type: application/json
| Parameter | Type | Required | Description |
|---|---|---|---|
| textColour | string | Required | Text colour as hex, e.g. "#333333" or "#333". |
| backgroundColour | string | Required | Background colour as hex, e.g. "#ffffff". |
| checkType | string Enum: wcag, custom | Optional | wcag tests AA and AAA for the font size; custom tests against customRatio.Default: wcag |
| fontSize | number | Optional | Font size in pixels, 1 to 1000. Used by the wcag check to decide if the text is large.Default: 14 |
| customRatio | number | Optional | Minimum contrast ratio, 1 to 21. Used by the custom check.Default: 4.5 |
Response Example
{
"success": true,
"checkType": "wcag",
"textColour": "#1a1a1a",
"backgroundColour": "#ffffff",
"fontSize": 16,
"isLargeText": false,
"contrastRatio": 17.4,
"wcagAA": true,
"wcagAAA": true
}Error Codes
400
Bad Request - Invalid hex colour or out-of-range value401
Unauthorized - Invalid or missing API key403
Forbidden - API key inactive, expired, or request from a disallowed IP429
Too Many Requests - Rate limit exceeded500
Internal Server ErrorPOST
https://opentools.ca/api/v1/tools/wcag-text-checker/batchCheck up to 100 colour pairs against WCAG AA and AAA
Request Body
Content-Type: application/json
| Parameter | Type | Required | Description |
|---|---|---|---|
| pairs | object[] | Required | 1 to 100 objects, each with textColour (string, required), backgroundColour (string, required) and fontSize (number, optional, default 14). |
Response Example
{
"success": true,
"count": 2,
"results": [
{
"textColour": "#000000",
"backgroundColour": "#ffffff",
"fontSize": 14,
"isLargeText": false,
"contrastRatio": 21,
"wcagAA": true,
"wcagAAA": true
},
{
"textColour": "#666666",
"backgroundColour": "#ffffff",
"fontSize": 14,
"isLargeText": false,
"contrastRatio": 5.74,
"wcagAA": true,
"wcagAAA": false
}
]
}Error Codes
400
Bad Request - Invalid hex colour, empty pairs, or more than 100 pairs (details names the field)401
Unauthorized - Invalid or missing API key403
Forbidden - API key inactive, expired, or request from a disallowed IP429
Too Many Requests - Rate limit exceeded500
Internal Server ErrorCode Examples
# One pair
curl -X POST https://opentools.ca/api/v1/tools/wcag-text-checker \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"textColour": "#333333", "backgroundColour": "#f5f5f5", "fontSize": 16}'
# Several pairs
curl -X POST https://opentools.ca/api/v1/tools/wcag-text-checker/batch \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"pairs": [{"textColour": "#000000", "backgroundColour": "#ffffff"}, {"textColour": "#0066cc", "backgroundColour": "#ffffff"}]}'Rather use it in your browser? Open the WCAG Text Contrast Checker