Color Converter API

Convert color codes between HEX, RGB, HSL, HWB and OKLCH. CSS keyword and Tailwind v3 matching, WCAG contrast ratios. Free, instant, no sign-up.

The Color Converter is also available as a free REST API. Send a POST request with a JSON body to https://dot.tools/api/tools/color-converter — no authentication, no API key, CORS enabled. Successful calls return { "ok": true, "result": { … } }; failures return HTTP 400 or 422 with an error body.

Request body

FieldTypeRequiredDescription
colorstringrequiredColor in any sRGB notation: #rgb/#rgba/#rrggbb/#rrggbbaa, rgb()/rgba(), hsl()/hsla(), hwb() (comma or space/slash syntax), or a CSS color keyword. OKLCH input is not accepted (out-of-gamut mapping), but OKLCH output is always provided.

Response

FieldTypeRequiredDescription
hexstringrequiredLowercase hex, 8 digits when alpha < 1 (e.g. #8b5cf6 or #8b5cf680).
rgbobjectrequired
hslobjectrequired
hwbobjectrequired
oklchobjectrequired
keywordunknownrequiredCSS keyword when the RGB channels exactly equal a named color, else null.
tailwindunknownrequiredNearest Tailwind v3 palette color, or null when the nearest match is farther than 0.1 OKLab units.
contrastOnWhitenumberrequiredWCAG contrast ratio against pure white, compositing alpha over white first. 2 decimals.
contrastOnBlacknumberrequiredWCAG contrast ratio against pure black, compositing alpha over black first. 2 decimals.

Example request

curl -X POST https://dot.tools/api/tools/color-converter \
  -H 'Content-Type: application/json' \
  -d '{
  "color": "#8b5cf6"
}'

Sample response

{
  "ok": true,
  "result": {
    "hex": "#8b5cf6",
    "rgb": {
      "r": 139,
      "g": 92,
      "b": 246,
      "a": 1
    },
    "hsl": {
      "h": 258.3,
      "s": 89.5,
      "l": 66.3,
      "a": 1
    },
    "hwb": {
      "h": 258.3,
      "w": 36.1,
      "b": 3.5,
      "a": 1
    },
    "oklch": {
      "l": 0.6056,
      "c": 0.2189,
      "h": 292.72,
      "a": 1
    },
    "keyword": null,
    "tailwind": {
      "name": "violet-500",
      "hex": "#8b5cf6",
      "distance": 0
    },
    "contrastOnWhite": 4.23,
    "contrastOnBlack": 4.96
  }
}

Use the free Color Converter in your browser, read the Color Converter guide, or import the full OpenAPI specification.