WCAG Contrast

GEThttps://api-colors.dataandapis.com/v1/colors/contrast

WCAG Contrast is an endpoint of the Colors API. Name, convert and check contrast for any color, with 31,919 curated names and WCAG math.

Send your key in the X-Api-Key header. Each call costs 1 token; a free key includes 500 tokens a month.

Request

Query parameters

ParameterExample
bgffffffRequired
fg000000Required

Example request

curl
curl "https://api-colors.dataandapis.com/v1/colors/contrast?bg=ffffff&fg=000000" \
  -H "X-Api-Key: YOUR_API_KEY"
Node.js
const res = await fetch("https://api-colors.dataandapis.com/v1/colors/contrast?bg=ffffff&fg=000000", {
  headers: { "X-Api-Key": process.env.DATAANDAPIS_KEY },
});
const data = await res.json();
Python
import os, requests

r = requests.get(
    "https://api-colors.dataandapis.com/v1/colors/contrast?bg=ffffff&fg=000000",
    headers={"X-Api-Key": os.environ["DATAANDAPIS_KEY"]},
)
data = r.json()

Example response

Example response
{
  "ok": true,
  "fg": "#000000",
  "bg": "#ffffff",
  "contrast_ratio": 21,
  "wcag": {
    "aa_normal_text": true,
    "aa_large_text": true,
    "aaa_normal_text": true,
    "aaa_large_text": true
  }
}