Skip to content
Custom properties · color-mix() · relative color · fallbacks

CSS Color Code Generator

Turn one color into shippable CSS — every format, a custom property, color-mix() button states, relative-color variants, an alpha scale and an OKLCH-with-fallback stack. Copy-paste, not just values.

01 · Color & token name
--
HEX
color: #6366f1;
rgb()
color: rgb(99 102 241);
hsl()
color: hsl(238.7, 83.5%, 66.7%);
oklch()
color: oklch(58.5% 0.204 277.1);
lab()
color: lab(50.1% 38.69 -70.49);
lch()
color: lch(50.1% 80.41 298.8);
02 · Deep analysis

Shippable CSS, not just values

Custom property + usage
:root {
  --brand: #6366f1;
}

.element {
  color: var(--brand);
}
OKLCH with HEX fallback (progressive)
.element {
  color: #6366f1;            /* fallback */
  color: oklch(58.5% 0.204 277.1);   /* modern */
}
Relative color variants
/* darker / lighter from one source */
--brand-dark:  oklch(from var(--brand) calc(l - 0.08) c h);
--brand-light: oklch(from var(--brand) calc(l + 0.10) c h);
Button states via color-mix()
base
hover
active
disabled
:root { --brand: #6366f1; }

.btn { background: var(--brand); color: #fff; }
.btn:hover  { background: color-mix(in oklch, var(--brand), black 12%); }
.btn:active { background: color-mix(in oklch, var(--brand), black 20%); }
.btn:focus-visible { outline: 2px solid color-mix(in oklch, var(--brand), white 25%); }
.btn:disabled { background: color-mix(in oklch, var(--brand), white 55%); }
Alpha scale

Click a step to copy rgb(r g b / a). Or token-safe: color-mix(in srgb, var(--brand) 50%, transparent).

Field notes

From a color value to shippable CSS

A color picker gives you a value; a stylesheet needs code — and the gap between the two is where a lot of avoidable boilerplate lives. The first move is almost always a custom property: declare --brand once on :root and reference it with var(--brand) everywhere, so the color has a single source of truth and can be re-themed by overriding the variable in a .dark scope. That one indirection is the foundation everything else builds on.

The modern CSS color functions then let you stop hard-coding derived colors. Instead of picking a second hex for hover, mix the token itself: color-mix(in oklch, var(--brand), black 12%) gives a perceptually-even darker shade that automatically follows the base color if it ever changes — and the same pattern yields active, disabled and focus-ring colors from one token. Relative color syntax goes further, letting you destructure a color's channels — oklch(from var(--brand) calc(l - 0.08) c h) — to compute variants the browser resolves at render time. Author once, derive the rest.

Adopting oklch() safely is just a matter of ordering. Declare the widely-supported value first and the modern one second — color: #6366f1; color: oklch(58% 0.21 277); — and the cascade does the right thing: capable browsers use OKLCH, older ones keep the HEX they already applied. No feature query, no risk. The same progressive instinct applies to alpha, where the slash syntax (rgb(r g b / .5)) and color-mix(… transparent) cover overlays and disabled fills.

So this generator emits not values but the lines you actually paste — the property, the states, the variants, the fallback stack — for whatever color you pick. Read the same color in every space with the Converter, build a whole system of these tokens in the Design Token Generator, and confirm the button's text passes contrast in the Accessibility Checker.

Deep-dive these colors — every hex has a full page

CSS Color Code FAQs

Have more questions? Contact us

Trusted by Front-End & Design-System Devs

4.8
Based on 2,760 reviews

This is the CSS-output tool I wanted — not just hex/rgb, but the custom property, the color-mix() button states, the relative-color darker/lighter variants, and a fallback stack. I paste the state snippet and my hover/active/disabled are derived from one token. Genuinely saves boilerplate every single component.

O
Owen Pierce
Front-end engineer
June 15, 2026

The color-mix-in-oklch hover/active snippet is exactly our convention, generated correctly with a live preview of each state. And the OKLCH-with-HEX-fallback stack means I can adopt modern CSS without breaking older browsers. Distinct from a plain converter — this outputs shippable CSS.

P
Priya Nair
Design systems dev
May 31, 2026

Alpha scale via slash syntax and color-mix-with-transparent, previewed over a checkerboard, is a nice touch I use for overlays. Relative color syntax examples taught me a pattern I now use everywhere. Would love a copy-as-SCSS option, but the CSS output is spot on.

L
Lukas Meyer
UI engineer
April 15, 2026

Custom property + var() usage + states + fallback, all from one color, all copy-paste. It made me finally move our tokens to oklch with confidence because the fallback stack is generated automatically. Pairs with the token generator for the full system.

S
Sara Lindqvist
Web developer
January 30, 2026

Your rating powers this tool’s public score — new reviews appear right here.

Connected instruments

Related color tools

From the blog

Keep reading, keep winning.

Pinboard · 0 picks

custom properties · color-mix() states · relative color · alpha · OKLCH+HEX fallback · Last reviewed: 2026-06