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.
color: #6366f1;color: rgb(99 102 241);color: hsl(238.7, 83.5%, 66.7%);color: oklch(58.5% 0.204 277.1);color: lab(50.1% 38.69 -70.49);color: lch(50.1% 80.41 298.8);Shippable CSS, not just values
:root {
--brand: #6366f1;
}
.element {
color: var(--brand);
}.element {
color: #6366f1; /* fallback */
color: oklch(58.5% 0.204 277.1); /* modern */
}/* 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);: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%); }Click a step to copy rgb(r g b / a). Or token-safe: color-mix(in srgb, var(--brand) 50%, transparent).
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.
Trusted by Front-End & Design-System Devs
“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.”
“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.”
“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.”
“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.”
Love using our calculator?
Related color tools
Similar Calculators
More tools in the same category
Multi-Format Color Converter
HEX, RGB, HSL, CMYK, LAB, LCH and OKLCH at once, live — with WCAG contrast, luminance and a tint/shade ramp.
Accessibility Color Checker
Test text/background pairs against WCAG AA/AAA contrast, with a one-click OKLCH fix and color-blind-aware guidance.
Color Scale Generator
Perceptually-even 50-950 shade scales from one base color, OKLCH-correct, with CSS export.
Color Palette Generator
Complementary, triadic, tetradic and more — harmonies generated in OKLCH with a live preview.
Gradient Palette Creator
Linear, radial and conic multi-stop gradients with a live preview and production CSS export.
Color Distance Calculator
Perceptual color difference via CIEDE2000, Delta-E 76 and OKLab — the print and brand-matching standard.
Often Used Together
Complementary tools for complete analysis
Related Articles
Dive deeper with our expert guides and tutorials related to CSS Color Code Generator
custom properties · color-mix() states · relative color · alpha · OKLCH+HEX fallback · Last reviewed: 2026-06