Defines colors, sizes, spacing, font names, or any other scalar CSS value.
Definition
Section titled “Definition”Defined with the --name: value; syntax.
--primary: #2060ff;--radius: 6px;--font-base: 16px;--theme: light;Written to :root
Section titled “Written to :root”These variables are moved to the :root block in the final CSS after compilation. They remain as live CSS custom properties in the browser.
--primary: #2060ff;--radius: 6px;
.btn { background: var(--primary); border-radius: var(--radius);}Generated CSS:
:root { --primary: #2060ff; --radius: 6px;}
.btn { background: var(--primary); border-radius: var(--radius);}Usage in Property Values
Section titled “Usage in Property Values”--spacing: 8px;--brand: #2060ff;--surface: #f4f6fb;
.card { padding: var(--spacing); background: var(--surface); border: 1px solid var(--brand);}Generated CSS:
:root { --spacing: 8px; --brand: #2060ff; --surface: #f4f6fb;}
.card { padding: var(--spacing); background: var(--surface); border: 1px solid var(--brand);}Usage Inside Selectors
Section titled “Usage Inside Selectors”A value variable can also be used as a selector part. This expansion is done at compile time.
--theme: light;--primary: #2060ff;
.btn-&var(--theme) { color: var(--primary);}Generated CSS:
:root { --theme: light; --primary: #2060ff;}
.btn-light { color: var(--primary);}Multiple Value Variables
Section titled “Multiple Value Variables”--color-brand: #2060ff;--color-surface: #f4f6fb;--color-text: #1a1a2e;--space-sm: 8px;--space-md: 16px;--space-lg: 24px;
.hero { background: var(--color-surface); color: var(--color-text); padding: var(--space-lg);}
.btn { background: var(--color-brand); color: var(--color-surface); padding: var(--space-sm) var(--space-md);}