Skip to content

Color converter

Convert any CSS color and check its contrast.

  • HEX #ffe04a
  • RGB rgb(255 224 74)
  • HSL hsl(50 100% 65%)
  • HWB hwb(50 29% 0%)
  • OKLCH oklch(90.7% 0.164 97.2)
  • Legacy RGB rgb(255, 224, 74)

Your files are open only in this tab. Nothing is uploaded.

Contrast (WCAG 2)

AA needs 4.5:1 for body text and 3:1 for large text. AAA needs 7:1. Alpha transparency is composited before scoring.

  • Aa On white 1.31:1 · Fails
  • Aa On black 16.01:1 · AAA
  • Aa White text 1.31:1 · Fails
  • Aa Black text 16.01:1 · AAA
  • Aa On #ffffff 1.31:1 · Fails

Shades

Lightest to darkest in OKLCH, keeping hue steady. Tap any shade to inspect it.

How to use Color converter

  1. Enter a color. Type any HEX, rgb(), hsl(), hwb(), oklch(), or named CSS color into the Color field, or use Pick a color.
  2. Copy formatted output. Click the copy button next to HEX, RGB, HSL, HWB, OKLCH, or Legacy RGB.
  3. Verify contrast ratios. Check the Contrast (WCAG 2) cards or type a custom surface value into Check against, including alpha values.
  4. Explore shade steps. Tap any swatch in the nine-step Shades grid to load that OKLCH tint or shade into the inspector.

Everything runs in this browser tab. Nothing you paste or open is uploaded or logged, so it's safe for keys, tokens and private data.

Converting CSS colors from HEX and RGB to OKLCH

Pasting any color into the Color input converts it simultaneously into six copy-ready formats: HEX, RGB, HSL, HWB, OKLCH, and Legacy RGB. Whether you start from a 3-digit #fff shorthand, an 8-digit 32 bit #rrggbbaa hex code over the 16 px checkerboard swatch, or a modern oklch() token, all outputs update instantaneously in your browser.

CSS Color Module Level 4 vs legacy comma syntax

Modern stylesheets follow the W3C CSS Color Module Level 4 Specification, which standardizes space-separated channel arguments and a forward slash before alpha transparency. That unified grammar lets rgb(), hsl(), hwb(), and oklch() share consistent syntax without switching between rgb() and rgba().

Because older email clients, PDF generators, and legacy codebases still expect comma-separated values, the output table also includes a Legacy RGB row alongside modern RGB, HSL, and HWB. If you need to sample brand colors from a screenshot or photograph before converting them, you can extract HEX and RGB swatches from any photo locally.

Resolving CSS named colors and angle units

Beyond numeric notation, the parser accepts CSS named keywords such as orange or rebeccapurple by resolving them through the browser’s own 2D Canvas fillStyle engine. It also normalizes angle suffixes across deg, turn, rad, and grad when reading hsl(), hwb(), or oklch() hues.

Input format Example syntax Alpha support Gamut behavior
HEX #ffe04a or #ffe04a80 4-digit and 8-digit hex Standard sRGB (0-255)
RGB / Legacy RGB rgb(255 224 74 / 0.8) Slash or 4th comma arg Standard sRGB (0-255)
HSL hsl(50 100% 65%) Slash or hsla() Standard sRGB
HWB hwb(50 29% 0%) Optional / alpha Standard sRGB
OKLCH / OKLab oklch(90.5% 0.165 98.1) Optional / alpha Clamped to sRGB if out of gamut
CSS Named rebeccapurple Opaque via canvas Resolved to sRGB

How do you convert OKLCH to sRGB without hue drift?

The converter transforms sRGB values through linear RGB into perceptual OKLab coordinates and then into cylindrical OKLCH (Lightness, Chroma, Hue), keeping perceived hue constant across tints and shades. When generating the nine-step palette, lightness steps smoothly from 97% down to 17% while scaling chroma proportionally so yellows do not turn muddy or blues shift purple.

Nine-step perceptual shade ramps in OKLCH

Traditional HSL palettes suffer from uneven perceived brightness: hsl(60 100% 50%) yellow appears far brighter than hsl(240 100% 50%) blue even though both claim 50% lightness. Under the MDN oklch() CSS Color Function, the L channel tracks human lightness perception directly, making it a dependable perceptual color picker for design systems.

Below the contrast panel, the Shades grid renders nine swatches from 97% lightness down to 17% lightness in OKLCH. Tapping any swatch loads its 8-bit HEX value back into the Color input so you can inspect its exact HSL, RGB, and Contrast (WCAG 2) scores.

Out-of-gamut Display P3 and sRGB clamping warnings

High-chroma oklch() or oklab() colors can describe vivid Display P3 tones that standard 8 bit sRGB monitors cannot represent. Whenever a parsed channel falls outside the [0, 255] sRGB range (beyond -0.5 or 255.5), an inline warning explains that HEX, RGB, and HSL outputs are clamped to the nearest displayable sRGB value.

Once your primary brand token and dark-mode shades are finalized, you can carry those exact hex values straight into the browser theme-color favicon generator to configure site.webmanifest and browser tab chrome.

WCAG contrast checker with alpha transparency

Accessibility audits often fail when designers test solid hex codes instead of the semi-transparent overlays actually rendered in CSS. The Contrast (WCAG 2) panel evaluates relative luminance and composites any alpha channel over the target background before assigning a pass or fail rating.

Scoring text against white, black, and custom backgrounds

Four cards score your active color automatically: On white, On black, White text, and Black text. Each card renders an Aa preview tile alongside a two-decimal ratio and a status badge: AAA (>= 7:1), AA (>= 4.5:1), AA large text only (>= 3:1), or Fails (< 3:1), matching the W3C WCAG 2.2 Contrast (Minimum) Success Criterion 1.4.3.

A fifth Check against input defaults to #ffffff and accepts any CSS color, letting you test custom surface tokens such as #141413 or oklch(0.95 0.02 90). High-contrast pairs matter outside UI text as well: you can verify foreground and background contrast for scannable QR codes before exporting SVG or PNG print assets.

How translucent foregrounds and backgrounds are composited

If your foreground color includes alpha (such as rgb(20 20 19 / 0.6)), the compositeOver helper blends it against the background first so the reported ratio reflects what users actually see. When the Check against background itself is translucent, the calculator evaluates the worst-case ratio across both white and black underlying surfaces.

Tip: Aim for at least 4.5:1 (AA) on interactive labels and form placeholders even when using muted grays, reserving 3:1 ratios strictly for large headings of 18 pt or 14 pt bold.

Design-system color tokens and asset workflows

Consistent UI engineering pairs well-structured CSS custom properties with lightweight visual assets. Keeping HEX fallbacks for legacy SVG icons alongside OKLCH tokens for modern browsers lets teams adopt perceptual color scales across 0% to 100% lightness without breaking older rendering engines.

When auditing a design system, test primary surfaces against #ffffff and #000000 first, then enter your dark-mode card background into Check against to confirm body copy clears 4.5:1 and headings meet at least 3:1. Saving both the OKLCH and RGB outputs beside each token documents exact fallback values for engineering handoffs.

When preparing marketing banners, social cards, or documentation graphics that use those brand palettes, run exported raster screenshots through Compress image to trim file size before publishing. Because every conversion, 9-step shade calculation, and WCAG luminance check runs locally in JavaScript, proprietary brand palettes and unreleased theme tokens stay private inside your browser tab.

Questions

Why use OKLCH instead of HSL for design systems?

HSL treats yellow and blue at 50% lightness as mathematically equal, even though yellow looks dramatically brighter to the human eye. OKLCH models human lightness perception directly, so changing lightness or chroma produces predictable contrast across every hue.

What contrast ratio does WCAG 2.2 require for text?

Level AA requires at least 4.5:1 for normal body text and 3:1 for large text at 18 pt or 14 pt bold. Level AAA raises the requirement to 7:1 for standard body copy.

How does alpha transparency affect WCAG contrast?

A semi-transparent foreground blends with the surface behind it before reaching the eye. This checker composites alpha over the target background first, and if the background itself is translucent it reports the worst-case score across white and black.

What is the difference between modern RGB and legacy RGB?

Modern CSS Color 4 syntax uses space-separated channels and a slash before alpha, such as rgb(255 224 74 / 0.5). Legacy syntax uses commas and a separate rgba() function name for transparent values.

Can I convert CSS named colors to HEX and RGB?

Yes. Standard keywords such as rebeccapurple, tomato, or cornflowerblue are resolved through the browser canvas parser and immediately output as HEX, RGB, HSL, HWB, and OKLCH.

What happens when an OKLCH color is outside sRGB?

Wide-gamut OKLCH colors that exceed standard sRGB bounds trigger an inline notice and clamp their HEX, RGB, and HSL outputs to the nearest displayable 0-255 sRGB channel values.

Updated