MiServe DevTools

Your lid

Pin tools here. They are saved in this browser.

Color Converter & Contrast Checker

Convert a colour between HEX, RGB, HSL, HWB, OKLCH and OKLab, check its WCAG contrast, and get a scale of tints and shades.

HEX
RGB
HSL
HWB
OKLCH
OKLab
Nearest CSS colour name

Contrast checker

Large text, set at 24 pixels

Normal text, set at 16 pixels. If this sentence is hard to read, the pair needs more contrast.

Contrast ratio (WCAG 2)

  • AA, normal text (4.5:1)
  • AA, large text (3:1)
  • AAA, normal text (7:1)
  • AAA, large text (4.5:1)

Tints and shades

The hue and chroma of the colour at eleven OKLCH lightness steps, with less chroma where sRGB cannot show it. Select a swatch to copy its hex code.

Runs in your browser. Nothing you paste is uploaded.

About this tool

Four notations for the same sRGB colour

HEX, RGB, HSL and HWB are four ways to write a colour in sRGB, the default colour space of the web. HEX and RGB give the red, green and blue channels directly, each from 0 to 255. HSL gives a hue angle, a saturation and a lightness; HWB gives the same hue angle with an amount of white and an amount of black mixed in. Converting between them changes the notation, not the colour.

An eight-digit hex code such as #5a3ff080, or a fourth value after a slash such as rgb(90 63 240 / 0.5), adds an alpha channel. The space-separated form is the CSS Color Level 4 syntax and works in every current browser; the comma form, rgba(90, 63, 240, 0.5), is there for older tools.

What OKLCH and OKLab add

OKLab is a colour space designed by Björn Ottosson in 2020 so that equal numeric steps look like equal steps to the eye. OKLCH is the same space in polar form: lightness from 0 to 1, chroma (how colourful) and a hue angle. Two OKLCH colours with the same lightness look about equally light, which is not true of HSL, where a yellow and a blue at 50% lightness differ widely.

OKLCH can also describe colours that an sRGB screen cannot show. When you enter one, this tool keeps its lightness and hue and lowers the chroma until the colour fits, and it tells you that it did so.

How the contrast ratio is calculated

WCAG 2 defines contrast as (L1 + 0.05) / (L2 + 0.05), where L1 and L2 are the relative luminance of the lighter and the darker colour. The result runs from 1:1 for two identical colours to 21:1 for black on white.

Level AA asks for at least 4.5:1 for normal text and 3:1 for large text; level AAA asks for 7:1 and 4.5:1. Large text means at least 24 CSS pixels, or about 18.7 pixels when bold. The ratio shown here is rounded down, because a pair measuring 4.499:1 does not meet 4.5:1.

How this tool computes the values

The conversions run in JavaScript in your browser, using the sRGB transfer function and the OKLab matrices published with the colour space. Each output is rounded to a few decimals, chosen so that the value converts back to the same 8-bit colour with these formulas. A browser may calculate OKLCH and OKLab with slightly different constants, so a pasted OKLCH or OKLab value can come out a step or two of 255 away in one channel, most often in a saturated green. The nearest named colour is the one at the smallest distance in OKLab.

Questions

Why did my OKLCH colour change when I converted it?

OKLCH can describe colours outside the sRGB gamut, and HEX, RGB and HSL cannot. The tool keeps the lightness and hue and reduces the chroma until the colour fits in sRGB, then shows the values of that colour.

What contrast ratio does WCAG AA require?

At least 4.5:1 for normal text and 3:1 for large text, which is text of 24 pixels or more, or about 18.7 pixels or more when bold. User interface components and meaningful graphics also need 3:1 against the colours next to them.

Is rgb(255 0 0) the same as rgb(255, 0, 0)?

Yes. The form with spaces is the current CSS syntax and is understood by every current browser. The form with commas is older and is still valid, so use it when a tool or an email client does not accept the newer one.

Does the contrast checker handle transparent colours?

Yes. A translucent text colour is first blended with the background, and a translucent background is blended with white, because the ratio depends on the colours that end up on the screen.

More in Graphics