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.