Skip to content
AliasCSS Logo
v1.5.6
Docs / Values and units

Values and units

Write values the way CSS writes them. A few characters need a special form, and CSS variables have a short syntax of their own.

The basics

You need Write Output
Several values - between them b-1px-solid-red → border: 1px solid red
A negative number -- before it m--8px → margin: -8px
A decimal . with a leading zero o-0.5, lh-1.5
A percentage % w-100%
A hex color with or without # c-e3e3e3 and c-#e3e3e3 are the same
A color with alpha / and a decimal from 0 to 1 c-red/0.5
!important --imp (or --important) at the end c-red--imp
m--8px
tf-translateY--2px
c-red/0.5
c-red--imp
Generated CSS
.m--8px {
  margin: -8px;
}
.tf-translateY--2px {
  transform: translateY(-2px);
}
.c-red\/0\.5 {
  color: oklch(from red l c h/0.5 );
}
.c-red--imp {
  color: red !important;
}

Alpha is always a decimal: c-red/0.5, never c-red/50. It compiles to a relative color, so it works with any color, including theme tokens and variables.

Property functions

When a value has spaces, commas or functions, write the property followed by its value in parentheses. Inside them, _ is a space and commas stay commas:

padding(8px_16px)
grid-template-columns(repeat(3,1fr))
box-shadow(0_1px_3px_rgb(0_0_0_/_0.1))
ff(ui-monospace,Menlo,monospace)
Generated CSS
.padding\(8px_16px\) {
  padding: 8px 16px;
}
.grid-template-columns\(repeat\(3\,1fr\)\) {
  grid-template-columns: repeat(3, 1fr);
}
.box-shadow\(0_1px_3px_rgb\(0_0_0_\/_0\.1\)\) {
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.1);
}
.ff\(ui-monospace\,Menlo\,monospace\) {
  font-family: ui-monospace, Menlo, monospace;
}

Two details:

  • Inside calc(), + and - need spaces around them, so write w(calc(100%_-_32px)). Without them the CSS is invalid and the browser drops it. * and / don’t need spaces.
  • _ means a space only inside parentheses. m-0_auto is not margin: 0 auto; write m-0-auto or margin(0_auto).

Chaining values with __

Properties that take a list, such as transform, transition-property and filter, chain values with a double underscore:

tf-translateY--2px__scale-1.02
transition-property-opacity__transform
Generated CSS
.tf-translateY--2px__scale-1\.02 {
  transform: translateY(-2px) scale(1.02);
}
.transition-property-opacity__transform {
  transition-property: opacity , transform;
}

CSS variables

Define a variable with --name:value, and use one by writing the property followed by --name:

--x-gap:16px
g--x-gap
g--x-gap:24px
m--x-shift:--8px
Generated CSS
.--x-gap\:16px {
  --x-gap: 16px;
}
.g--x-gap {
  gap: var(--x-gap);
}
.g--x-gap\:24px {
  gap: var(--x-gap, 24px);
}
.m--x-shift\:--8px {
  margin: var(--x-shift, -8px);
}
Write Means
--x-gap:16px defines --x-gap: 16px
--x-pad:(8px_16px) defines a raw value: --x-pad: 8px 16px
g--x-gap gap: var(--x-gap)
g--x-gap:16px gap: var(--x-gap, 16px), with a fallback
m--x-shift:--8px a negative fallback is written with -- too

Start your variable names with --x-. Short selector aliases own many two-letter prefixes (--h- is :hover, --s- is ::selection, --sb- is the scrollbar), so --sb-bg:red compiles as a scrollbar rule instead of a variable.

The end of a variable’s name decides how its value is compiled. Names ending in color or bg compile color tokens, so a theme token works as a value:

--x-card-bg:slateTheme2
bgc--x-card-bg:slateTheme1
Generated CSS
.--x-card-bg\:slateTheme2 {
  --x-card-bg: light-dark(#f9f9fb,#18191b);
}
.bgc--x-card-bg\:slateTheme1 {
  background-color: var(--x-card-bg,light-dark(#fcfcfd,#111113));
}

Names that end in anything else keep the value as written.

Anchor and timeline names

Some properties take a dashed name: anchor-name, position-anchor, anchor-scope, animation-timeline, scroll-timeline, view-timeline (and their -name forms), timeline-scope, position-try and font-palette. In these, AliasCSS adds the -- for you, and --name is the name itself, not a variable. Tie a popover or tooltip to its button with the same name on both:

anchor-name-x-menu
position-anchor-x-menu
position-area(bottom_span-right)
Generated CSS
.anchor-name-x-menu {
  anchor-name: --x-menu;
}
.position-anchor-x-menu {
  position-anchor: --x-menu;
}
.position-area\(bottom_span-right\) {
  position-area: bottom span-right;
}
Class Output
anchor-name-menu, anchor-name--menu anchor-name: --menu
anchor-name-menu__card anchor-name: --menu, --card
position-anchor-auto position-anchor: auto (keywords stay keywords)
scroll-timeline-hero_y scroll-timeline: --hero y
position-try-fallbacks(--below,flip-block) position-try-fallbacks: --below, flip-block
anchor-name--var--x anchor-name: var(--x), when you do want a variable