foreground string required Opaque foreground sRGB color in #rgb or #rrggbb notation. The # must be URL-encoded as %23 in a request URL.
Calculate WCAG 2.2 contrast for two opaque sRGB hex colors, including exact relative luminance and AA/AAA normal- and large-text results.
Authoritative reference data or standards computation
Canonicalizes two opaque sRGB hex colors, returns their relative luminance and evaluates the four WCAG text thresholds.
| Parameter | Type | Default & allowed | Description |
|---|---|---|---|
foreground
required
| string | allowed: 1 – 32 example: #111827 | Opaque foreground sRGB color in #rgb or #rrggbb notation. The # must be URL-encoded as %23 in a request URL. |
background
required
| string | allowed: 1 – 32 example: #ffffff | Opaque background sRGB color in #rgb or #rrggbb notation. Alpha and non-hex CSS color syntax are rejected. |
foreground string required Opaque foreground sRGB color in #rgb or #rrggbb notation. The # must be URL-encoded as %23 in a request URL.
background string required Opaque background sRGB color in #rgb or #rrggbb notation. Alpha and non-hex CSS color syntax are rejected.
| Parameter | Type | Default & allowed | Description |
|---|---|---|---|
fields | list | example: foreground,background | Return only these fields (comma-separated). Mutually exclusive with 'exclude'. |
exclude | list | example: passesAaaLargeText | Return all fields except these (comma-separated). |
pretty | boolean | default: false example: true | Pretty-print the JSON response. |
unwrap | boolean | default: false example: true | Drop the envelope: return the raw array/object without data/meta wrapper. |
fields list Return only these fields (comma-separated). Mutually exclusive with 'exclude'.
exclude list Return all fields except these (comma-separated).
pretty boolean Pretty-print the JSON response.
unwrap boolean Drop the envelope: return the raw array/object without data/meta wrapper.
| Field | Type | Description | Example |
|---|---|---|---|
foreground | string (hex color) | Canonical lowercase six-digit foreground color. | #111827 |
background | string (hex color) | Canonical lowercase six-digit background color. | #ffffff |
foregroundLuminance | float | WCAG relative luminance of the foreground, from 0 through 1. | 0.009955 |
backgroundLuminance | float | WCAG relative luminance of the background, from 0 through 1. | 1 |
contrastRatio | float | WCAG contrast ratio from 1 through 21. | 17.739 |
passesAaNormalText | boolean | Whether the ratio is at least 4.5:1 for WCAG AA normal text. | true |
passesAaLargeText | boolean | Whether the ratio is at least 3:1 for WCAG AA large text. | true |
passesAaaNormalText | boolean | Whether the ratio is at least 7:1 for WCAG AAA normal text. | true |
passesAaaLargeText | boolean | Whether the ratio is at least 4.5:1 for WCAG AAA large text. | true |
foreground string (hex color) Canonical lowercase six-digit foreground color.
example: #111827
background string (hex color) Canonical lowercase six-digit background color.
example: #ffffff
foregroundLuminance float WCAG relative luminance of the foreground, from 0 through 1.
example: 0.009955
backgroundLuminance float WCAG relative luminance of the background, from 0 through 1.
example: 1
contrastRatio float WCAG contrast ratio from 1 through 21.
example: 17.739
passesAaNormalText boolean Whether the ratio is at least 4.5:1 for WCAG AA normal text.
example: true
passesAaLargeText boolean Whether the ratio is at least 3:1 for WCAG AA large text.
example: true
passesAaaNormalText boolean Whether the ratio is at least 7:1 for WCAG AAA normal text.
example: true
passesAaaLargeText boolean Whether the ratio is at least 4.5:1 for WCAG AAA large text.
example: true
/api/color-contrast/check?foreground=%23111827&background=%23ffffff {
"data": {
"foreground": "#111827",
"background": "#ffffff",
"foregroundLuminance": 0.009189219295824108,
"backgroundLuminance": 1,
"contrastRatio": 17.73971700407407,
"passesAaNormalText": true,
"passesAaLargeText": true,
"passesAaaNormalText": true,
"passesAaaLargeText": true
},
"meta": {
"endpoint": "color-contrast",
"route": "/check",
"params": {
"foreground": "#111827",
"background": "#ffffff"
},
"generatedAt": "2026-07-29T08:13:22.000Z"
}
} /api/color-contrast/check?foreground=%23fff&background=%232563eb {
"data": {
"foreground": "#ffffff",
"background": "#2563eb",
"foregroundLuminance": 1,
"backgroundLuminance": 0.15315153582201535,
"contrastRatio": 5.168555560022562,
"passesAaNormalText": true,
"passesAaLargeText": true,
"passesAaaNormalText": false,
"passesAaaLargeText": true
},
"meta": {
"endpoint": "color-contrast",
"route": "/check",
"params": {
"foreground": "#ffffff",
"background": "#2563eb"
},
"generatedAt": "2026-07-29T08:13:22.000Z"
}
} /api/color-contrast/check?foreground=%23777&background=%23fff {
"data": {
"foreground": "#777777",
"background": "#ffffff",
"foregroundLuminance": 0.184474994500441,
"backgroundLuminance": 1,
"contrastRatio": 4.478089453577214,
"passesAaNormalText": false,
"passesAaLargeText": true,
"passesAaaNormalText": false,
"passesAaaLargeText": false
},
"meta": {
"endpoint": "color-contrast",
"route": "/check",
"params": {
"foreground": "#777777",
"background": "#ffffff"
},
"generatedAt": "2026-07-29T08:13:22.000Z"
}
} Checks two opaque sRGB colors against the contrast-ratio requirements in WCAG 2.2. Pass a foreground and background in strict #rgb or #rrggbb notation; shorthand is expanded and both inputs are canonicalized to lowercase six-digit hex in the response and meta.params.
Each sRGB channel is linearized with the current WCAG breakpoint of 0.04045, then combined as 0.2126 R + 0.7152 G + 0.0722 B. The lighter and darker relative luminances produce (L1 + 0.05) / (L2 + 0.05), a ratio from 1 to 21.
The four booleans apply the WCAG thresholds directly: AA normal text ≥4.5, AA large text ≥3, AAA normal text ≥7 and AAA large text ≥4.5. “Large” has the WCAG meaning (at least 18 point, or 14 point when bold); this API evaluates contrast only and does not infer a font's size or weight.
Alpha, CSS names, rgb(), wide-gamut color spaces and gradients are deliberately rejected. Transparent colors require compositing against a known background first, so accepting them here would create a misleading ratio.
It checks AA normal text at 4.5:1, AA large text at 3:1, AAA normal text at 7:1 and AAA large text at 4.5:1.
Yes. It linearizes sRGB channels with the current 0.04045 breakpoint and applies the WCAG relative-luminance coefficients before calculating the ratio.
No. Alpha is rejected because contrast depends on compositing; provide the final opaque foreground and background colors instead.
Only opaque #rgb and #rrggbb sRGB hex values are accepted. Encode the # as %23 in a URL.
Random colors in hex, RGB and HSL with hue and luminosity filters, nearest CSS color names and WCAG contrast text — plus deterministic color-scheme palettes.
Sparkline SVGs straight from a URL — plot 2–100 numbers as a line, area or bar chart with custom size, color and smoothing. No chart library needed.
Hotlinkable SVG placeholder images at any size from 8 to 4000 px — custom label, colors and an optional gradient. Deterministic and crisp at every scale.
Deterministic SVG avatars from any seed string — identicons, initials and abstract shapes. Same seed, same avatar forever; plus ready-to-use avatar URL batches.
Real, scannable SVG barcodes — EAN-13 with automatic check digits and Code 128 set B. Custom height, optional label, deterministic and safe to hotlink.
Simulate protanopia, deuteranopia and tritanopia on your colors with cited Brettel 1997, Viénot 1999 or Machado 2009 matrices, and flag pairs that converge.