CSS Variables (Custom Properties)

Atomic CSS can directly reference CSS custom properties (variables) as classes. Use variables defined in :root with HTML classes alone — no additional CSS needed.

Core Rule: prefix--variable-nameproperty: var(--variable-name)

How It Works

Define variables in :root, reference them with Atomic classes, and CSS is auto-generated.

/* :root definition */
:root {
  --primary: #6366f1;
  --spacing: 16px;
  --radius: 8px;
}

/* Use with Atomic CSS classes */
<div class="bg--primary gap--spacing br--radius">
  ...
</div>

/* Generated CSS */
.bg--primary { background-color: var(--primary); }
.gap--spacing { gap: var(--spacing); }
.br--radius { border-radius: var(--radius); }

Syntax

Class names connect a CSS property prefix and variable name with a double hyphen (--).

prefix--variable-name
PartDescriptionExample
prefixCSS property abbreviation prefix (same as standard Atomic rules)bg, w, gap
--Double hyphen — separator indicating a variable reference
variable-nameCSS custom property name (the part after --)primary, spacing-md

Colors

Manage text, background, and border colors with variables.

ClassCSSDescription
c--textcolor: var(--text)Text color
bg--primarybackground-color: var(--primary)Background color
bc--borderborder-color: var(--border)Border color
btc--accentborder-top-color: var(--accent)Top border color
fill--iconfill: var(--icon)SVG fill color
stroke--linestroke: var(--line)SVG stroke color
<!-- Define variables in :root -->
<style>
:root {
  --primary: #6366f1;
  --surface: #18181b;
  --text: #fafafa;
  --muted: #71717a;
  --border: #27272a;
}
</style>

<!-- Use with Atomic CSS -->
<div class="bg--surface c--text b1pxsolid--border br8px p2rem">
  <h2 class="c--primary fs2rem fw700">Heading</h2>
  <p class="c--muted fs14px">Description text</p>
</div>

Spacing

Unify margin, padding, gap, and position values with variables.

ClassCSSDescription
m--spacingmargin: var(--spacing)All margins
mt--header-hmargin-top: var(--header-h)Top margin
p--card-padpadding: var(--card-pad)All padding
gap--grid-gapgap: var(--grid-gap)Grid/flex gap
rg--row-gaprow-gap: var(--row-gap)Row gap
cg--col-gapcolumn-gap: var(--col-gap)Column gap
t--nav-htop: var(--nav-h)Top offset
<style>
:root {
  --page-pad: 2.4rem;
  --card-gap: 16px;
  --section-gap: 4rem;
}
</style>

<!-- Consistent spacing with variables -->
<main class="p--page-pad">
  <section class="mb--section-gap">
    <div class="dg gtcr3-1fr gap--card-gap">
      <div class="p--page-pad bg18181B br8px">Card</div>
      <div class="p--page-pad bg18181B br8px">Card</div>
      <div class="p--page-pad bg18181B br8px">Card</div>
    </div>
  </section>
</main>

Sizing

ClassCSSDescription
w--sidebar-wwidth: var(--sidebar-w)Width
h--hero-hheight: var(--hero-h)Height
maxw--containermax-width: var(--container)Max width
minh--screenmin-height: var(--screen)Min height

Typography

ClassCSS
fs--bodyfont-size: var(--body)
fw--headingfont-weight: var(--heading)
lh--bodyline-height: var(--body)
ff--monofont-family: var(--mono)
ls--wideletter-spacing: var(--wide)

Border & Radius

ClassCSS
br--radiusborder-radius: var(--radius)
bw--border-wborder-width: var(--border-w)
btw--dividerborder-top-width: var(--divider)

Grid & Flex

ClassCSS
gtc--colsgrid-template-columns: var(--cols)
gtr--rowsgrid-template-rows: var(--rows)
gac--auto-colgrid-auto-columns: var(--auto-col)
fb--basisflex-basis: var(--basis)
fg--growflex-grow: var(--grow)

Effects & Others

ClassCSS
zi--modalz-index: var(--modal)
o--fadeopacity: var(--fade)
bxs--cardbox-shadow: var(--card)
ts--glowtext-shadow: var(--glow)
fltr--blurfilter: var(--blur)
trf--movetransform: var(--move)
trn--smoothtransition: var(--smooth)
ar--videoaspect-ratio: var(--video)

Combinations

CSS variable classes can be freely combined with media queries, pseudo-classes, and !important.

Media Query + Variable

<!-- Responsive: different variable per breakpoint -->
<div class="bg--primary md-bg--primary-md sm-bg--primary-sm">
  Responsive color
</div>

<!-- Variable-based responsive spacing -->
<section class="p--desktop-pad md-p--tablet-pad sm-p--mobile-pad">
  Content
</section>

Pseudo-class + Variable

<!-- Hover: change to accent color -->
<button class="bg--primary hover-bg--accent c--text cp py8px px16px br8px bn">
  Hover me
</button>

<!-- Focus: outline with variable color -->
<input class="focus-olc--ring focus-visible-olc--ring" />

<!-- Pseudo-element -->
<div class="before-bg--accent">Decorated</div>

!important + Variable

<!-- !important suffix: add 'i' at the end -->
<div class="bg--surfacei c--texti">
  Styles with !important
</div>

<!-- Generated CSS -->
<!-- .bg--surfacei { background-color: var(--surface) !important; } -->
<!-- .c--texti { color: var(--text) !important; } -->

Shorthand Decomposition

p, m, gap, bw are shorthands that decompose into individual directions.

ClassGenerated CSS
p--spacepadding-top/right/bottom/left: var(--space)
m--spacemargin-top/right/bottom/left: var(--space)
gap--spacerow-gap: var(--space); column-gap: var(--space)
bw--lineborder-top/right/bottom/left-width: var(--line)

Practical Example — Design System

Using variables enables consistent, design-token-based UI.

<style>
:root {
  --primary: #6366f1;
  --surface: #111113;
  --surface-hover: #18181b;
  --text: #fafafa;
  --muted: #71717a;
  --border: #27272a;
  --radius: 12px;
  --gap: 16px;
  --pad: 2rem;
}
</style>

<!-- Design system powered by variables -->
<div class="dg gtcr3-1fr gap--gap sm-gtc1fr">
  <article class="bg--surface b1pxsolid--border br--radius p--pad hover-bg--surface-hover tall200msease">
    <h3 class="c--text fs16px fw700 mb8px">Card Title</h3>
    <p class="c--muted fs14px m0 lh1-6">Card description text</p>
  </article>
</div>

Dark Mode Toggle

Just swap :root variables and the same Atomic classes switch between light and dark mode.

/* Light mode */
:root {
  --bg: #ffffff;
  --text: #1a1a2e;
  --border: #e4e4e7;
  --primary: #6366f1;
}

/* Dark mode */
:root.dark {
  --bg: #09090b;
  --text: #fafafa;
  --border: #27272a;
  --primary: #818cf8;
}

/* Same Atomic classes work in both modes */
/* <div class="bg--bg c--text b1pxsolid--border"> */

Tips & Cautions

Supported Prefixes

Only prefixes listed in the full reference below support CSS variables. Unsupported prefixes are ignored.

neg- Not Allowed

The neg- prefix cannot be used with CSS variable classes. Define negative values in the variable itself if needed.

:root Definition Required

Atomic CSS only references variables. The actual values must be defined in :root or a separate CSS file.

Full Prefix Reference

Complete list of all prefixes that support CSS variables.

Color

PrefixCSS PropertyExample
ccolorc--text
bgbackground-colorbg--primary
bcborder-colorbc--border
btcborder-top-colorbtc--accent
brcborder-right-colorbrc--accent
bbcborder-bottom-colorbbc--accent
blcborder-left-colorblc--accent
fillfillfill--icon
strokestrokestroke--line

Spacing

PrefixCSS PropertyExample
mmargin (shorthand)m--space
mtmargin-topmt--gap
mrmargin-rightmr--gap
mbmargin-bottommb--gap
mlmargin-leftml--gap
ppadding (shorthand)p--pad
ptpadding-toppt--pad
prpadding-rightpr--pad
pbpadding-bottompb--pad
plpadding-leftpl--pad
gapgap (shorthand)gap--grid
rgrow-gaprg--row
cgcolumn-gapcg--col
ttopt--offset
rrightr--offset
bbottomb--offset
lleftl--offset

Sizing

PrefixCSS PropertyExample
wwidthw--sidebar
hheighth--hero
maxwmax-widthmaxw--container
maxhmax-heightmaxh--modal
minwmin-widthminw--btn
minhmin-heightminh--page

Typography

PrefixCSS PropertyExample
fsfont-sizefs--body
fwfont-weightfw--bold
lhline-heightlh--body
fffont-familyff--mono
lsletter-spacingls--wide
wsword-spacingws--loose
titext-indentti--indent

Border & Radius

PrefixCSS PropertyExample
brborder-radiusbr--radius
bwborder-width (shorthand)bw--line
btwborder-top-widthbtw--divider
brwborder-right-widthbrw--line
bbwborder-bottom-widthbbw--line
blwborder-left-widthblw--line

Grid & Flex

PrefixCSS PropertyExample
gtcgrid-template-columnsgtc--layout
gtrgrid-template-rowsgtr--rows
gtagrid-template-areasgta--areas
gacgrid-auto-columnsgac--auto
gargrid-auto-rowsgar--auto
gcsgrid-column-startgcs--start
gcegrid-column-endgce--end
grsgrid-row-startgrs--start
gregrid-row-endgre--end
fgflex-growfg--grow
fbflex-basisfb--basis

Effects & Others

PrefixCSS PropertyExample
ziz-indexzi--modal
oopacityo--fade
bxsbox-shadowbxs--card
tstext-shadowts--glow
fltrfilterfltr--blur
bdfltrbackdrop-filterbdfltr--glass
trftransformtrf--move
trntransitiontrn--smooth
animanimationanim--fade
araspect-ratioar--video