Colors and themes
Use any CSS color, or theme tokens that switch between light and dark on their own. One variable rebrands the accent color everywhere.
Any CSS color
Named colors, hex (with or without #), rgb(), oklch() and every other CSS color work as values. Add / and a decimal for alpha:
c-red
c-6366f1
bgc-rgb(10,12,16)
c-oklch(0.6_0.2_280)
bgc-6366f1/0.15Generated CSS
.c-red {
color: red;
}
.c-6366f1 {
color: #6366f1;
}
.bgc-rgb\(10\,12\,16\) {
background-color: rgb(10,12,16);
}
.c-oklch\(0\.6_0\.2_280\) {
color: oklch(0.6 0.2 280);
}
.bgc-6366f1\/0\.15 {
background-color: oklch(from #6366f1 l c h/0.15 );
}Theme tokens
AliasCSS ships the Radix color scales as tokens that hold a light and a dark value. Steps 1–2 are backgrounds, 3–5 are component fills, 6–8 are borders, 9–10 are solid colors, and 11–12 are text.
<div class="d-flex flex-wrap-wrap g-8px">
<span class="p-8px-12px br-6px bgc-slateTheme3 c-slateTheme12">slate</span>
<span class="p-8px-12px br-6px bgc-blueTheme3 c-blueTheme11">blue</span>
<span class="p-8px-12px br-6px bgc-greenTheme3 c-greenTheme11">green</span>
<span class="p-8px-12px br-6px bgc-amberTheme3 c-amberTheme11">amber</span>
<span class="p-8px-12px br-6px bgc-redTheme3 c-redTheme11">red</span>
</div>Generated CSS
.d-flex {
display: flex;
}
.flex-wrap-wrap {
flex-wrap: wrap;
}
.g-8px {
gap: 8px;
}
.p-8px-12px {
padding: 8px 12px;
}
.br-6px {
border-radius: 6px;
}
.bgc-slateTheme3 {
background-color: light-dark(#f0f0f3,#212225);
}
.c-slateTheme12 {
color: light-dark(#1c2024,#edeef0);
}
.bgc-blueTheme3 {
background-color: light-dark(#e6f4fe,#0d2847);
}
.c-blueTheme11 {
color: light-dark(#0d74ce,#70b8ff);
}
.bgc-greenTheme3 {
background-color: light-dark(#e6f6eb,#132d21);
}
.c-greenTheme11 {
color: light-dark(#218358,#3dd68c);
}
.bgc-amberTheme3 {
background-color: light-dark(#fff7c2,#302008);
}
.c-amberTheme11 {
color: light-dark(#ab6400,#ffca16);
}
.bgc-redTheme3 {
background-color: light-dark(#feebec,#3b1219);
}
.c-redTheme11 {
color: light-dark(#ce2c31,#ff9592);
}Switch this site between light and dark with the button in the header and the swatches follow.
| Tokens | What they are |
|---|---|
slateTheme1 … slateTheme12 |
Light/dark scale. Also red, green, amber, blue, crimson, pink, violet, teal, orange and the other Radix scales. |
slateDark1 … slateDark12 |
The dark values only. |
blackA1 … blackA12 |
Black with alpha. |
accentRA100 … accentRA1600 |
An accent scale built from one color (fixed). |
accentRATheme100 … accentRATheme1600 |
The same accent scale, light and dark. |
Turn theming on
Theme tokens compile to light-dark(), which needs a color-scheme. Add x-theme to <html>. It also sets the page background and text color:
<html class="x-theme">
The page now follows the operating system’s light or dark setting. To force one, add x-theme-dark or x-theme-light, either to <html> or to any part of the page:
<html class="x-theme x-theme-dark">
<aside class="x-theme-light">Always light</aside>
Rebrand with one variable
The accentRA scales are computed from --accentColor. Change it once and every accent shade changes with it. This site uses the landing page’s indigo:
<html class="x-theme --accentColor:6366f1">
<div class="d-flex flex-wrap-wrap g-8px --accentColor:0d9488">
<span class="p-8px-12px br-6px bgc-accentRATheme100 c-accentRATheme1100">soft</span>
<span class="p-8px-12px br-6px bgc-accentRATheme1000 c-white">solid</span>
<span class="p-8px-12px br-6px b-1px-solid-accentRATheme600 c-accentRATheme1100">outline</span>
</div>Generated CSS
.d-flex {
display: flex;
}
.flex-wrap-wrap {
flex-wrap: wrap;
}
.g-8px {
gap: 8px;
}
.--accentColor\:0d9488 {
--accentColor: #0d9488;
}
.p-8px-12px {
padding: 8px 12px;
}
.br-6px {
border-radius: 6px;
}
.bgc-accentRATheme100 {
background-color: light-dark(oklch(from var(--accentColor,oklch(1 .25049 284.23)) 98.1187% calc(l * c * 0.5) h),oklch(from var(--accentColor,oklch(1 .25049 284.23)) 29.6725% calc(l * c * 0.5) h));
}
.c-accentRATheme1100 {
color: light-dark(oklch(from var(--accentColor,oklch(1 .25049 284.23)) 46.9058% c h),oklch(from var(--accentColor,oklch(1 .25049 284.23)) 72.3297% c h));
}
.bgc-accentRATheme1000 {
background-color: light-dark(oklch(from var(--accentColor,oklch(1 .25049 284.23)) 51.9076% c h),oklch(from var(--accentColor,oklch(1 .25049 284.23)) 67.0121% c h));
}
.c-white {
color: white;
}
.b-1px-solid-accentRATheme600 {
border: 1px solid light-dark(oklch(from var(--accentColor,oklch(1 .25049 284.23)) 72.3297% c h),oklch(from var(--accentColor,oklch(1 .25049 284.23)) 57.9699% c h));
}One known issue: inside a forced subtree (x-theme-dark on a light page), slateTheme tokens switch correctly but accentRATheme tokens keep the page’s scheme in Chrome. Prefer slate tokens in parts of the page you force.
Gradients
Define two color variables once and use them in the gradient. Variable names ending in color compile tokens, so the gradient follows the theme and the accent:
<div class="--x-from-color:accentRA900 --x-to-color:pinkTheme9 h-48px br-8px background(linear-gradient(135deg,var(--x-from-color),var(--x-to-color)))"></div>Generated CSS
.--x-from-color\:accentRA900 {
--x-from-color: oklch(from var(--accentColor,oklch(1 .25049 284.23)) 57.9699% c h);
}
.--x-to-color\:pinkTheme9 {
--x-to-color: light-dark(#d6409f,#d6409f);
}
.h-48px {
height: 48px;
}
.br-8px {
border-radius: 8px;
}
.background\(linear-gradient\(135deg\,var\(--x-from-color\)\,var\(--x-to-color\)\)\) {
background: linear-gradient(135deg, var(--x-from-color), var(--x-to-color));
}