Skip to content

Color Converter guide

Tool guide. Updated .

How to convert colours between HEX, RGB, HSL and OKLCH with the XGM Color Converter, and how to check WCAG contrast ratios for readable text.

Colour formats

Screens mix red, green and blue light, and most colour formats on the web are different ways of writing the same sRGB values. HEX and rgb() give the channel values directly, HSL describes hue, saturation and lightness, and OKLCH describes colours in a space designed so that equal changes look like equal changes to the eye. The XGM converter shows all of them for one colour.

The same blue in four formats
FormatValueNotes
HEX#1a5fd0Two hex digits per channel; #rgb shorthand and 8-digit forms with alpha exist
RGBrgb(26 95 208)Channels 0–255; older syntax uses commas
HSLhsl(217 78% 46%)Hue in degrees, saturation and lightness in percent
OKLCHoklch(51.4% 0.187 260)Perceptual lightness, chroma and hue
What the converter doesA colour is parsed from HEX, rgb() or hsl(), converted to the other formats, and compared with a background colour to calculate the WCAG contrast ratio.Parse the inputHEX, rgb() or hsl(), with optional alphaConvertHEX, RGB, HSL and OKLCH values for the samecolourRelative luminanceLinearised sRGB channels weighted per WCAGContrast ratio with the background(L1 + 0.05) / (L2 + 0.05), from 1:1 to 21:1WCAG levelsAA and AAA for normal and large text
A colour is parsed from HEX, rgb() or hsl(), converted to the other formats, and compared with a background colour to calculate the WCAG contrast ratio.

How to use the Color Converter

  1. Open the Color Converter and enter a colour as HEX, rgb() or hsl().
  2. Copy the format you need from the table of colour formats.
  3. Enter a background colour to check contrast; use Swap colours to test the reverse.
  4. Read the contrast ratio and the AA and AAA results for normal and large text, with a preview.

Test the real pairs your design uses: body text on the page background, link colour on the background, button text on the button colour and hint text in inputs. Each pair has its own ratio.

WCAG contrast requirements

The Web Content Accessibility Guidelines (WCAG) define contrast as a ratio between the relative luminance of two colours, from 1:1 (identical) to 21:1 (black on white). Low contrast makes text hard to read for people with low vision, colour vision deficiencies, or anyone using a phone in sunlight.

WCAG 2.2 contrast thresholds
LevelNormal textLarge textUser interface components
AA (1.4.3, 1.4.11)4.5:13:13:1 for borders, icons and focus indicators
AAA (1.4.6)7:14.5:1No additional requirement

Large text means at least 18 point (24 CSS pixels) regular, or 14 point (about 18.66 CSS pixels) bold. The preview shows a 24 px sample so you can judge the large-text case visually as well as by the number.

Transparent colours

Contrast depends on what is behind a semi-transparent colour. Blend it with its actual background first, then check the resulting opaque colour.

Why OKLCH is useful

In HSL, colours with the same lightness value can look very different in brightness: a yellow at 50% lightness looks much lighter than a blue at 50%. OKLCH's lightness is designed to match perception, so changing only the hue keeps the apparent brightness close to the same. That makes it easier to build colour palettes and to predict contrast.

A palette with steady lightness in CSS
:root {
  --brand: oklch(0.52 0.17 262);
  --brand-hover: oklch(0.46 0.17 262);
  --success: oklch(0.52 0.12 150);
  --danger: oklch(0.52 0.18 27);
}

Modern browsers support oklch() in CSS. OKLCH can also describe colours outside the sRGB gamut that wide-gamut displays can show; the converter works with sRGB colours, so its OKLCH values stay within what every screen can display.

Fixing a failing colour pair

When a pair fails, change lightness first and keep the hue. Darkening a text colour or lightening a background by small steps usually reaches 4.5:1 without changing the character of the design. In OKLCH this is especially predictable: lower the first value (lightness) and check again.

Example adjustments on a white background
ColourContrast with #ffffffResult
#7aa7f0 light blueabout 2.4:1Fails AA for text and UI components
#3b82f6 medium blueabout 3.7:1Passes large text and UI components only
#1a5fd0 darker blueabout 5.9:1Passes AA for normal text
#1e3a8a navyabove 10:1Passes AAA

Keep a lighter tint for decorative uses such as backgrounds of badges and illustrations, and a darker shade of the same hue for text and icons. Design systems often define both as separate tokens so nobody accidentally uses the light tint for text.

Dark themes need their own checks rather than inverted values. Pure white text on pure black reaches 21:1 but can feel harsh; a slightly softer text colour on a dark grey surface still passes AAA comfortably and is easier on the eyes.

Practical tips for accessible colour

  • Check both light and dark themes; a colour that passes on white often fails on a dark surface.
  • Do not rely on colour alone to convey meaning; add text or icons to errors and status badges.
  • Keep link colour distinguishable from body text by more than hue, for example with an underline.
  • Test focus indicators against both the component and the page background.
  • Define colours as design tokens so contrast fixes happen in one place.

Contrast is one part of accessibility. For a page such as https://www.example.com, automated checkers catch many contrast issues, but real pairs in hover states, disabled controls and overlays need manual checks with a tool like this one.

FAQ

What contrast ratio do I need for body text?

At least 4.5:1 for WCAG AA, and 7:1 for AAA. Large text needs 3:1 for AA and 4.5:1 for AAA.

What counts as large text?

At least 24 CSS pixels at normal weight, or about 18.66 CSS pixels bold (18pt and 14pt).

Is HEX or RGB better?

They describe the same sRGB values. HEX is compact; rgb() is easier to read and edit. Use whichever your codebase uses consistently.

Why do HSL colours with the same lightness look different?

HSL lightness is a simple formula, not a perceptual measure. OKLCH lightness is designed to match how bright colours appear.

Does the converter support transparency?

It reads alpha values, but contrast should be checked on the colour as it appears over its real background.

Can I use OKLCH in CSS?

Yes, all current major browsers support oklch(). Provide a fallback only if you must support much older browsers.

Why does white text on my brand colour fail?

Mid-lightness brand colours often reach only around 3:1 with white. Darken the colour for text backgrounds, or use dark text on it.

Are colours uploaded?

No. Conversion and contrast calculation run in your browser.

What contrast do buttons and form borders need?

WCAG 2.2 success criterion 1.4.11 asks for 3:1 against adjacent colours for the visual parts needed to identify controls, such as input borders and focus indicators. The text inside the button follows the normal text rules.

Why does the same colour look different on my phone?

Displays differ in brightness, gamut and colour calibration, and many phones adjust colours automatically. The HEX value is the same; its appearance is not, which is why contrast is measured mathematically.

Does passing contrast guarantee accessibility?

No. It covers one requirement. Font size, spacing, focus visibility, keyboard access and meaningful structure matter too.

Sources