WCAG Text Contrast Checker

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 fontSize of 18 px or more. Bold text between 14 px and 18 px is not treated as large here.

Endpoints

  • POST /v1/tools/wcag-text-checker checks one pair. checkType is wcag (default) or custom.
  • POST /v1/tools/wcag-text-checker/batch checks 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-checker
Check the contrast of one colour pair

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
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
Optionalwcag tests AA and AAA for the font size; custom tests against customRatio.Default: wcag
fontSize
number
OptionalFont size in pixels, 1 to 1000. Used by the wcag check to decide if the text is large.Default: 14
customRatio
number
OptionalMinimum 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 value
401
Unauthorized - Invalid or missing API key
403
Forbidden - API key inactive, expired, or request from a disallowed IP
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error
POST
https://opentools.ca/api/v1/tools/wcag-text-checker/batch
Check up to 100 colour pairs against WCAG AA and AAA

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
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 key
403
Forbidden - API key inactive, expired, or request from a disallowed IP
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error

Code 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"}]}'

Ready to get started?

Create an API key to start using the WCAG Text Contrast Checker API.

Rather use it in your browser? Open the WCAG Text Contrast Checker