oktools

Color Converter & Contrast Checker

A color converter and color contrast checker in one: hex to rgb, rgb to hex, HSL, OKLCH, HSV and CMYK, with the WCAG AA and AAA verdict for any text and background pair as you go. Paste any CSS colour — a hex, a function, or a name — and everything is worked out in your browser.

HEX#3366CC
RGBrgb(51, 102, 204)
HSLhsl(220, 60%, 50%)
OKLCHoklch(53.25% 0.16787 262.29)
HSVhsv(220, 75%, 80%)
CMYKcmyk(75%, 50%, 0%, 20%)
Try:
HEX#FFFFFF
RGBrgb(255, 255, 255)
HSLhsl(0, 0%, 100%)
OKLCHoklch(100% 0 0)
HSVhsv(0, 0%, 100%)
CMYKcmyk(0%, 0%, 0%, 0%)
CSS namewhite
Try:

Contrast checker

5.37:1Contrast ratio
PassAA · normal text
FailAAA · normal text
Nearest shade of this colour that passes AAA: #1E4FB3 at 7.43:1

Preview at every text size

The quick brown fox jumps over the lazy dog

The quick brown fox jumps over the lazy dog

The quick brown fox jumps over the lazy dog

The quick brown fox jumps over the lazy dog

The quick brown fox jumps over the lazy dog

Button

12px Smaller than anything AA is written for

16px Normal text — needs 4.5:1 for AA, 7:1 for AAA

24px Large text (18pt) — needs 3:1 for AA, 4.5:1 for AAA

14pt bold Also counts as large text — needs 3:1 for AA

28px bold A heading, comfortably large text

How it works

Whatever is typed into either field is parsed into one sRGB colour with an alpha channel, and every readout beside it — HEX, RGB, HSL, OKLCH, HSV, CMYK and the CSS name — is produced from that single value. The parser reads hex in three, four, six or eight digits with or without the hash, rgb() and hsl() in either syntax, hue in degrees, radians, gradians or turns, oklch() with lightness as a percentage or a 0–1 number, and the CSS colour names. A value it cannot read leaves the last good colour in place and says so.

OKLCH is computed by undoing the sRGB transfer curve, mixing the linear channels through the cone-response matrix, taking cube roots and projecting to Oklab; chroma and hue are the polar form of its a and b, and the steps run backwards for an oklch() input. OKLCH can name colours no sRGB screen can show; such a value is pulled in by reducing its chroma with a sixteen-step binary search, keeping lightness and hue, and a notice says so. The shades are nine steps of OKLCH lightness, 0.1 to 0.9, at the colour’s own hue and chroma, so they step evenly where an HSL ramp bunches up.

The contrast ratio follows WCAG 2.1: each colour’s relative luminance is the weighted sum of its linearised channels (0.2126 red, 0.7152 green, 0.0722 blue), and the ratio is the lighter luminance plus 0.05 over the darker plus 0.05. The background is composited over white and the text over the background first, so a translucent colour is judged as what the eye sees. The suggestion keeps the text colour’s OKLCH hue and chroma, walks its lightness in steps of 0.025, snaps each candidate to the hex it will be applied as, and offers the nearest that reaches 4.5:1, or 7:1 once AA holds.

Examples

Convert a hex colour to every format

HSL and OKLCH are written the way CSS accepts them. HSV is what Figma and Photoshop call HSB, and CMYK is the plain conversion with no print profile; both are for reading.

Input
#3366CC
Output
HEX    #3366CC
RGB    rgb(51, 102, 204)
HSL    hsl(220, 60%, 50%)
OKLCH  oklch(53.25% 0.16787 262.29)
HSV    hsv(220, 75%, 80%)
CMYK   cmyk(75%, 50%, 0%, 20%)

Check translucent text against a background

Black at 60% opacity is composited over the white first, which gives the grey #666666 and a ratio of 5.74:1. A checker that ignores alpha would measure pure black and report 21:1.

Colours
text: rgba(0, 0, 0, 0.6)
background: #FFFFFF
Verdict
5.74:1
AA · normal text   Pass
AAA · normal text  Fail
WCAG levels: AA Pass, AA Large Pass, AAA Fail, AAA Large Pass, UI Pass

Fix a colour that fails AA

The first three lines are what Copy pair puts on the clipboard. The suggestion is the same hue in OKLCH, only darker; Use it applies it, and the Shades view shows the whole ramp.

Colours
text: #9999FF
background: #FFFFFF
Result
text: #9999FF
background: #FFFFFF
contrast: 2.51:1 (fails AA)
Nearest shade of this colour that passes AA: #6E6BCC at 4.53:1

Read an OKLCH colour that sRGB cannot show

A chroma of 0.35 at this hue is outside sRGB, so it came down to 0.1928 while lightness and hue were kept; the last line is how the notice above the contrast card begins.

Input
oklch(70% 0.35 150)
Output
HEX    #00BE58
RGB    rgb(0, 190, 88)
OKLCH  oklch(70% 0.19278 150)

One of these colours was written in OKLCH with more chroma than sRGB can show, so its chroma was reduced until it fit.

Supported formats

  • Hex#RGB, #RGBA, #RRGGBB and #RRGGBBAA, with or without the hash, in either case. Output is always upper-case #RRGGBB, with the alpha pair added only when alpha is below 1.
  • rgb() and hsl()Commas or spaces, channels as 0–255 or percentages, hue as a bare number, deg, rad, grad or turn, alpha after a comma or a slash. Written back as rgb(51, 102, 204) and hsl(220, 60%, 50%).
  • oklch()Lightness as a percentage or a 0–1 number, chroma as a number or a percentage where 100% is 0.4, hue in any CSS angle unit, alpha after a slash. Written back as oklch(53.25% 0.16787 262.29).
  • Named colours and transparentAll 148 CSS colour names, aliceblue to yellowgreen, in any case, plus transparent. A colour that matches a name exactly gets a CSS name row, so #663399 shows rebeccapurple.
  • Picker, eyedropper and read-only modelsThe swatch opens the browser’s colour picker; in Chrome and Edge a Pick button samples any pixel on screen through the EyeDropper API. HSV and CMYK are read-only, since CSS has no function for either.

Use cases

  • Choose a text colour that passes AA on a brand backgroundPaste both colours, read the ratio and, if it falls short, take the suggestion. #767676 on white is the lightest grey that passes AA, at 4.54:1; the page then offers #535353 at 7.69:1 for AAA.
  • Build a tint and shade scale from one colourThe Shades view is nine steps of perceptual lightness at the colour’s hue, the 100-to-900 scale of a design-system token set, each marked with the ratio it reaches on the current background.
  • Translate between a design tool and CSSFigma, Sketch and Photoshop pickers show HSB and hex; stylesheets want rgb(), hsl() or oklch(). Paste one and copy the other, or move a palette to oklch() with the values the page writes.
  • Check icons, borders and focus ringsNon-text parts of an interface need 3:1 under WCAG 1.4.11. The WCAG levels view lists that UI row beside the text thresholds, and the preview draws a button outline in the text colour.

Limitations

  • sRGB onlyDisplay P3, Rec. 2020 and the color(), lab() and lch() functions are not read, and an OKLCH colour outside sRGB is shown at reduced chroma. Wide-gamut work needs a library such as Color.js.
  • CMYK has no print profileThe CMYK line is the plain formula a design tool shows without an ICC profile. A print shop’s profile gives different percentages; set it in the layout application rather than copying these.
  • WCAG 2 contrast, not APCAThe ratio and thresholds are WCAG 2.1, which is what audits cite. The APCA model proposed for WCAG 3 scores some pairs very differently; an APCA calculator is the place for that.
  • The suggestion moves lightness onlyHue and chroma are kept on purpose, so when no lightness of that hue reaches the target nothing is offered — mid-grey on mid-grey has nowhere to go. Change the background or the hue instead.
  • Values are rounded for displayHSL and HSV to one decimal, OKLCH chroma to four and hue to two, alpha to three. Round trips return the same hex; a pipeline that needs unrounded numbers should keep the HEX form.

Frequently asked questions

How do I convert a HEX colour to RGB or HSL?

Paste the hex value into either colour field and the RGB, HSL, OKLCH, HSV and CMYK equivalents appear beside it, each with a copy button. It works from any direction: paste rgb(), hsl(), oklch() or a CSS colour name and the other formats follow.

What is OKLCH and why would I use it?

OKLCH describes a colour as perceptual lightness, chroma and hue. Unlike HSL, equal steps in it look like equal steps to the eye, so lightening or darkening a colour keeps its character instead of washing it out. It is supported in every current browser and is the reason the shades below step evenly.

What contrast ratio do I need to pass WCAG?

WCAG 2 asks for at least 4.5:1 for normal body text and 3:1 for large text — 18pt, or 14pt bold — to reach level AA. Level AAA raises those to 7:1 and 4.5:1. Icons, borders and other non-text parts of an interface need 3:1 against what is next to them.

My colour fails AA — how do I fix it without losing the brand?

Use the suggestion under the ratio. It moves only the perceptual lightness of your colour and leaves hue and chroma alone, so the result is the nearest shade of the same colour that passes rather than a different colour that happens to. The shades view shows the whole ramp with the ratio each shade reaches.

Does it handle transparency?

Yes. Alpha is read from #RRGGBBAA, rgba(), hsla() and the oklch() slash syntax, and semi-transparent text is composited over the background before the ratio is worked out — which is what the eye actually sees, and what a checker that ignores alpha gets wrong.

Are my colours sent anywhere?

No. Every conversion and every contrast calculation runs in your browser. Nothing about the palette you are working on is uploaded, stored or logged.