Colour contrast checker

Check the WCAG contrast ratio between text and background colours, with AA and AAA pass or fail.

Input

The text colour, in any CSS format.
The background colour, in any CSS format.

Result

Fill in the input and press Run.

Your input is processed in memory and then discarded. It is not stored or logged. Even so, don't paste live passwords or keys into any online tool.

Use it from code or an agent

curl -s https://setget.net/v1/tools/contrast-ratio \
  -H 'Content-Type: application/json' \
  -d '{"input":{"foreground":"#000000","background":"#ffffff"}}'
import json, urllib.request

body = {'input': {'foreground': '#000000', 'background': '#ffffff'}}
request = urllib.request.Request("https://setget.net/v1/tools/contrast-ratio", json.dumps(body).encode(),
                                 {"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(request))["result"])
const response = await fetch("https://setget.net/v1/tools/contrast-ratio", {
  method: "POST",
  headers: {"Content-Type": "application/json"},
  body: JSON.stringify({"input":{"foreground":"#000000","background":"#ffffff"}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
  "slug": "contrast-ratio",
  "input": {
    "foreground": "#000000",
    "background": "#ffffff"
  }
}
{
  "input": {
    "foreground": "#000000",
    "background": "#ffffff"
  }
}

Endpoint: POST /v1/tools/contrast-ratio. Over MCP: run_tool with slug: "contrast-ratio". Machine-readable: input schema, Markdown. Connect an agent.

Inputs

NameTypeRequiredWhat it does
foreground string yes The text colour, in any CSS format.
background string yes The background colour, in any CSS format.

Examples

Input
{
  "foreground": "#000000",
  "background": "#ffffff"
}
Result
{
  "ratio": 21,
  "text": "21:1",
  "foreground": "#000000",
  "background": "#ffffff",
  "aa": {
    "normal": true,
    "large": true
  },
  "aaa": {
    "normal": true,
    "large": true
  },
  "ui_components": true,
  "suggestion": null
}

A grey that just fails

Input
{
  "foreground": "#777777",
  "background": "#ffffff"
}
Result
{
  "ratio": 4.47,
  "text": "4.47:1",
  "foreground": "#777777",
  "background": "#ffffff",
  "aa": {
    "normal": false,
    "large": true
  },
  "aaa": {
    "normal": false,
    "large": false
  },
  "ui_components": true,
  "suggestion": {
    "foreground": "#767676",
    "ratio": 4.54,
    "passes": "AA"
  }
}

Questions

What ratios are needed?
AA needs 4.5:1 for normal text and 3:1 for large text. AAA needs 7:1 and 4.5:1. Icons and interface components need 3:1.
What counts as large text?
At least 18 point (24 px), or 14 point (about 18.7 px) when bold.
Why does 4.47 not round up to pass?
WCAG compares the exact ratio, so 4.499 fails 4.5. The ratio shown is cut to two decimals, never rounded up.
How is the suggestion chosen?
It keeps the hue and saturation of your text colour and changes the lightness by the smallest amount that reaches AA for normal text.
What about transparent colours?
A see-through foreground is blended over the background first, and a see-through background is blended over white.