Skip to content
AliasCSS Logo
v1.5.6
Docs / Animation

Animation

Transitions and transforms are ordinary declarations. Keyframes are written as an attribute on an element, so an animation lives next to the markup it moves.

Transitions

Write the transition properties as you would in CSS, chaining lists with __. The function form takes a full shorthand:

transition-property-opacity__transform
transition-duration-0.2s
transition(opacity_.2s,transform_.2s)
Generated CSS
.transition-property-opacity__transform {
  transition-property: opacity , transform;
}
.transition-duration-0\.2s {
  transition-duration: 0.2s;
}
.transition\(opacity_\.2s\,transform_\.2s\) {
  transition: opacity .2s, transform .2s;
}

Respect reduced motion with a scope:

@motion-reduce-transition-duration-0s
Generated CSS
@media (prefers-reduced-motion: reduce) {
  .\@motion-reduce-transition-duration-0s {
    transition-duration: 0s;
  }
}

Transforms

Chain transform functions with __. They’re applied in the order written:

<div class="d-flex g-24px p-8px">
<div class="w-64px h-64px br-12px bgc-accentRATheme1000 tf-rotate-12deg"></div>
<div class="w-64px h-64px br-12px bgc-accentRATheme1000 tf-translateY--8px__scale-0.9"></div>
<div class="w-64px h-64px br-12px bgc-accentRATheme1000 tf-perspective-400px__rotateY-35deg"></div>
</div>
Generated CSS
.d-flex {
  display: flex;
}
.g-24px {
  gap: 24px;
}
.p-8px {
  padding: 8px;
}
.w-64px {
  width: 64px;
}
.h-64px {
  height: 64px;
}
.br-12px {
  border-radius: 12px;
}
.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));
}
.tf-rotate-12deg {
  transform: rotate(12deg);
}
.tf-translateY--8px__scale-0\.9 {
  transform: translateY(-8px) scale(0.9);
}
.tf-perspective-400px__rotateY-35deg {
  transform: perspective(400px) rotateY(35deg);
}

If something else sets transform inline on the element (positioning libraries often do), use the separate rotate, translate and scale properties instead. They combine with the inline transform instead of being overwritten by it: rotate-180deg, not tf-rotate-180deg.

Keyframes

A keyframes-name attribute defines @keyframes name. Each stop is @percent-[classes], or @percent-class for a single class:

Pop in Wobble
<i class="d-none" keyframes-pop-in="@0-[o-0,tf-scale-0.9] @100-[o-1,tf-none]"></i>
<i class="d-none" keyframes-wobble="@[0,100][tf-none] @[20,60][tf-rotate--4deg] @[40,80][tf-rotate-4deg]"></i>

<div class="d-flex g-12px">
<span class="p-8px-14px br-8px bgc-slateTheme3 animation(pop-in_.6s_ease-out_infinite_alternate)">Pop in</span>
<span class="p-8px-14px br-8px bgc-slateTheme3 animation(wobble_1s_ease-in-out_infinite) @motion-reduce-animation-none">Wobble</span>
</div>
Generated CSS
@keyframes pop-in {
  0% {
    opacity: 0;
    transform: scale(0.9);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}
@keyframes wobble {
  0%,100% {
    transform: none;
  }
  20%,60% {
    transform: rotate(-4deg);
  }
  40%,80% {
    transform: rotate(4deg);
  }
}
.d-none {
  display: none;
}
.d-flex {
  display: flex;
}
.g-12px {
  gap: 12px;
}
.p-8px-14px {
  padding: 8px 14px;
}
.br-8px {
  border-radius: 8px;
}
.bgc-slateTheme3 {
  background-color: light-dark(#f0f0f3,#212225);
}
.animation\(pop-in_\.6s_ease-out_infinite_alternate\) {
  animation: pop-in .6s ease-out infinite alternate;
}
.animation\(wobble_1s_ease-in-out_infinite\) {
  animation: wobble 1s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  .\@motion-reduce-animation-none {
    animation: none;
  }
}
  • One stop: @0-[…], @0[…] or @50%[…]. The dash and the % are optional.
  • Several stops with the same styles: @[0,25,50][…].
  • A single class needs no brackets: @25-tf-translateY-3px, @25dn or @[25]-dn. Two or more classes go in brackets.
  • Stops are numbers. from and to aren’t accepted; write 0 and 100.
  • Inside the brackets, classes are separated by commas. Commas inside parentheses are left alone: @0-[transform(translate(0,0)_scale(1)),o-1].
  • Names are lower-case kebab-case. HTML lower-cases attribute names, so keyframes-fadeIn becomes fadein.
  • Give the element a class (class="d-none"). The browser script’s first pass only visits elements that have one; the CLI doesn’t care.

Use the animation with animation(name_duration_easing_…) or the separate properties (animation-name-pop-in, animation-duration-0.3s).

Staggered lists

Set an index on each item and compute the delay from it:

<li style="--i:0" class="animation(pop-in_.3s_ease-out_both) animation-delay(calc(var(--i)_*_40ms))">…</li>
<li style="--i:1" class="animation(pop-in_.3s_ease-out_both) animation-delay(calc(var(--i)_*_40ms))">…</li>

Replaying an animation

To play a one-shot animation again, toggle an attribute on a parent that turns it on: [data-play]&animation(shake_.45s_ease-in-out) animates the element while any ancestor has data-play. Remove the attribute, read element.offsetWidth, and add it back. To use an attribute on the element itself, leave out the &: [data-play]-animation(…). In React, change the element’s key.

Entry transitions without keyframes

@starting-style sets where an element starts when it appears. With transition-behavior-allow-discrete, popovers and dialogs can fade in and out using transitions alone:

o-0
--popover-open-o-1
@starting-style--popover-open-o-0
transition-property-opacity__display__overlay
transition-duration-0.2s
transition-behavior-allow-discrete
Generated CSS
.o-0 {
  opacity: 0;
}
.--popover-open-o-1:popover-open {
  opacity: 1;
}
@starting-style {
  .\@starting-style--popover-open-o-0:popover-open {
    opacity: 0;
  }
}
.transition-property-opacity__display__overlay {
  transition-property: opacity , display , overlay;
}
.transition-duration-0\.2s {
  transition-duration: 0.2s;
}
.transition-behavior-allow-discrete {
  transition-behavior: allow-discrete;
}