Skip to content

Colour Converter & Contrast Checker

Convert a colour between HEX, RGB, HSL and OKLCH and check WCAG contrast against white, black or any colour. Runs entirely in your browser.

Runs entirely in your browser. Nothing you paste here is sent to us or anyone else โ€” there is no server processing, no logging of input, and no third-party scripts on this page.

A colour converter turns one colour into every format you need โ€” HEX, RGB, HSL and OKLCH โ€” while a contrast checker tells you whether text in that colour is readable against its background under the WCAG accessibility guidelines. Type or pick a colour above and all four formats update live next to a swatch; the contrast panel scores it against white, black and any colour you choose. Everything happens in your browser and nothing you enter is transmitted anywhere.

The four colour formats

The same colour can be written many ways, and each format is suited to a different job:

Format Example Best for
HEX #2F81F7 Compact, universal in CSS, design tools and markup.
RGB rgb(47, 129, 247) Reasoning about raw red, green and blue channels or adding alpha.
HSL hsl(214, 93%, 58%) Tweaking hue, saturation and lightness by hand.
OKLCH oklch(61.82% 0.1935 258.33) Perceptually even lightness and clean gradients.

Why OKLCH is worth learning

HSL is convenient but deceptive: two colours with the same lightness value can look wildly different in brightness, and blending two hues in HSL often passes through a dull grey. OKLCH is built on the OKLab colour space, which was designed so that a given change in lightness or hue looks like the same amount of change to the human eye. That makes it excellent for building colour scales, tinting and shading systematically, and producing gradients that stay vivid all the way across. This tool computes OKLCH the correct way โ€” converting sRGB to linear light, into the OKLab cone response, and out to lightness, chroma and hue โ€” rather than faking it with a rough formula.

Reading the contrast checker

Web Content Accessibility Guidelines (WCAG) express legibility as a contrast ratio between two colours, from 1:1 (identical) up to 21:1 (pure black on pure white). The checker shows the ratio of your colour against a comparison colour and marks each conformance level:

  • AA normal text โ€” needs at least 4.5:1. This is the baseline most sites should meet for body copy.
  • AA large text โ€” needs at least 3:1. Large means roughly 24px, or 18.66px if bold.
  • AAA normal text โ€” needs at least 7:1, the enhanced level for maximum readability.
  • AAA large text โ€” needs at least 4.5:1.

By default you see the score against both white and black, so you can tell at a glance whether light or dark text sits better on your colour. Enter a custom comparison colour to test a real foreground and background pair.

A worked example

Take the blue #2F81F7. As RGB it is rgb(47, 129, 247); as HSL, hsl(214, 93%, 58%); as OKLCH, oklch(61.82% 0.1935 258.33). Against white its contrast is about 3.75:1 โ€” enough for large headings under AA, but short of the 4.5:1 needed for normal body text. Against black it reaches about 5.60:1, comfortably passing AA for normal text. So white text on this blue works for big headings, while black text is the safer choice for smaller copy.

Common pitfalls

  • Assuming a nice colour is accessible. Mid-tone colours frequently fail against both black and white; always verify rather than eyeball it.
  • Forgetting large-text rules. A colour that fails for body text may be perfectly fine for a big headline, which only needs 3:1.
  • Testing transparent colours. Contrast is defined for opaque colours, so flatten any semi-transparent layer against its real backdrop first.
  • Trusting a single round-trip. HSL degrees and percentages are rounded for readability, so re-parsing them can shift a value by one unit โ€” harmless, but worth knowing.

Privacy

This converter runs entirely on your device using the browser built-in colour picker and plain JavaScript maths. There is no server round-trip, no logging and no third-party analytics on the page, so you can safely check brand or client colours here โ€” or run the tool offline once it has loaded.

Frequently asked questions

Is my colour sent to a server?

No. Every conversion and contrast calculation runs in your browser with plain JavaScript. Nothing is uploaded, logged, or stored, and the tool keeps working with the network disconnected once the page has loaded.

What colour formats can I paste in?

HEX (3, 4, 6 or 8 digits, with or without the leading hash), rgb() and rgba(), and hsl() and hsla(). You can also use the native colour picker. The four output formats โ€” HEX, RGB, HSL and OKLCH โ€” update live as you type.

What is OKLCH and why should I care?

OKLCH is a modern colour space (lightness, chroma, hue) built on OKLab. Its lightness is perceptually uniform, so equal changes look equally different to the eye, and interpolating between OKLCH colours avoids the muddy greys you get halfway through an HSL or RGB gradient. It is supported in all current browsers via the CSS oklch() function.

How is the OKLCH value calculated?

The sRGB channels are converted to linear light, transformed into the OKLab LMS cone space, cube-rooted, mapped to OKLab, then expressed as lightness, chroma and hue. That is the exact transform published by Bjorn Ottosson, not an approximation.

What contrast ratio do I need to pass WCAG?

For AA, normal text needs a ratio of at least 4.5:1 and large text at least 3:1. For the stricter AAA level, normal text needs 7:1 and large text 4.5:1. Large text means 18.66px bold or 24px and above.

Does the contrast checker account for opacity?

No. WCAG contrast is defined for opaque colours, so alpha is ignored when computing the ratio. If your text or background is semi-transparent, flatten it against its actual backdrop first, then check that resulting colour here.

Why does the HSL or RGB value shift by one when I round-trip it?

Converting between colour spaces involves rounding to whole channels or degrees. A HEX value maps to exact bytes, but HSL percentages and hue degrees are rounded for readability, so re-parsing a rounded HSL string can land one unit away. The underlying colour is effectively identical.

Can I check contrast against a colour other than black or white?

Yes. The comparison field takes any HEX, RGB or HSL value, or use its colour picker. The tool shows the ratio and AA/AAA pass or fail badges for your custom colour as well as for white and black.