Convert

Convert a colour

One colour in, three notations and two contrast ratios out.

Accepts #rgb, #rrggbb, #rrggbbaa, rgb(), rgba() and hsl(), because those are the forms a colour arrives in when it is copied out of CSS, a design tool or a screenshot.

The contrast ratios use the WCAG 2.1 relative-luminance formula. 4.5:1 is the AA threshold for normal text, 3:1 for large text, and 7:1 is AAA. The numbers are the calculation itself rather than an approximation, so they match a contrast checker.

What it cannot tell you is whether the colour works: a ratio says nothing about legibility at 12 pixels on a phone in daylight, and nothing about colour blindness. It answers the one question it can answer exactly.

Questions

Is 4.5:1 a pass?

It is AA for normal-size text. Large text — 18.66px bold or 24px regular — passes at 3:1, and AAA needs 7:1.

Does transparency affect the ratio?

In reality yes: a transparent colour composites with its background. The ratio here is for the colour at full opacity.

Why is my HSL different from the design tool?

Rounding. Hue is reported as a whole degree and saturation and lightness as whole percent, which is how CSS usually shows them.

Is the colour sent anywhere?

No. Parsing and the formula both run in the page.

More text and code