For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /guide/animations/index.md.

Animations

Animate your UI with:

  • CSS transitions and CSS @keyframes
  • an element's animate() method
  • for content that appears and disappears, Angular's animate.enter and animate.leave, or the LynxTransition component

Choose an approach

You want toUseDetails
Change a color, size or position smoothly when state changesCSS transitionBelow
Loop an animation, or play a fixed sequence (spinner, pulse)CSS @keyframesBelow
Start an animation from code, with keyframes chosen at runtimeThe element's animate() methodAnimate from code
Animate content as it appears and disappearsanimate.enter and animate.leaveEnter and leave transitions
Animate content in and out with a timing you setLynxTransitionLynxTransition
Move an element with a finger, frame by frameA main-thread scriptMain-thread scripts
Angular's animation APIs

Angular's animate.enter and animate.leave work, with CSS classes or with a function of your own: see Enter and leave transitions. Its older @angular/animations package (trigger(), state(), transition()) isn't supported. Use the approaches on this page instead.

Lynx elements do have an animate() method that looks like the browser's Web Animations API. It's Lynx's own version: it returns a handle with only play(), pause() and cancel(). See Animate from code.

CSS transitions

Put transition on an element, then change a property by toggling a class from a signal:

src/app/fade.ts
import { Component, signal } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-fade',
  imports: [LYNX_ELEMENTS],
  template: `
    <view class="box" [class.active]="active()" (bindtap)="toggle()">
      <text>Tap me</text>
    </view>
  `,
  styles: `
    .box {
      width: 100px;
      height: 100px;
      background-color: #a1a1aa;
      transition: background-color 0.5s ease-in-out; /* [!code highlight] */
    }
    .active {
      background-color: #6366f1;
    }
  `,
})
export class Fade {
  readonly active = signal(false);

  toggle(): void {
    this.active.update((v) => !v);
  }
}
  • The handler only sets a signal, which is always safe in an event handler. Angular updates the class after it returns.
  • A transition runs when a property changes on an element that's already on screen. It doesn't run when the element first appears: use animate.enter or LynxTransition for that.
  • Only some properties animate.
  • Write time values with a unit: 0ms, not 0. Lynx ignores a bare 0.

Keep a transition moving while your app works

Lynx works out each frame of an animation itself, on the thread your Angular code runs on. So a frame Angular spends building a screen is a frame nothing moves.

Put enable-new-animator="false" on an element to hand its transitions and @keyframes to the platform instead:

  • iOS uses Core Animation, which keeps them moving whatever the app is doing.
  • Android uses its animators.

Add flatten="false" too: Android only animates a transform on an element with a view of its own.

<view
  enable-new-animator="false"
  flatten="false"
  class="drawer"
  [class.open]="open()"
></view>
  • The element's animate() method does nothing then: move it with transition and @keyframes.
  • On iOS, transform, opacity and background-color animate, and the element's position and size, though its background and children take the new size at once: move it with transform and opacity.
  • Start the transition with afterFrame() after work such as building a screen. iOS begins it at the time of the last frame the app saw, so one started straight after a busy moment is partway through when it's first drawn.
  • <lynx-stack-outlet> moves its screens this way, and the Bottom Sheet its sheet. The Spinner, Skeleton and indeterminate Progress run their loops on the platform too, so they keep going while a screen builds, which is when they show.
  • The web preview ignores the attribute: the browser runs the transition.

CSS @keyframes

Define @keyframes in your component styles, and start the animation by adding a class:

src/app/spin.ts
import { Component, signal } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-spin',
  imports: [LYNX_ELEMENTS],
  template: `
    <view class="spinner" [class.spinning]="spinning()" (bindtap)="toggle()">
      <text>Spin</text>
    </view>
  `,
  styles: `
    @keyframes rotate {
      from {
        transform: rotate(0deg);
      }
      to {
        transform: rotate(360deg);
      }
    }
    .spinner {
      width: 80px;
      height: 80px;
      background-color: #f97316;
    }
    .spinning {
      animation: rotate 1s linear infinite; /* [!code highlight] */
    }
  `,
})
export class Spin {
  readonly spinning = signal(false);

  toggle(): void {
    this.spinning.update((v) => !v);
  }
}
  • Adding the spinning class starts the animation from its first frame, and removing it stops the animation.
  • infinite in the animation shorthand loops it. Use a number to play it that many times.
  • A loop that shows while the app works, such as a spinner, stops while Angular is busy unless the platform runs it: give its element enable-new-animator="false" and flatten="false" (see above). A rotate() from 0deg to 360deg turns there too.

Animate from code

Call animate() on an element you get with viewChild():

src/app/pulse.ts
import { Component, type ElementRef, viewChild } from '@angular/core';
import { LYNX_ELEMENTS } from '@blotch/angular-lynx';

@Component({
  selector: 'app-pulse',
  imports: [LYNX_ELEMENTS],
  template: `
    <view #box (bindtap)="pulse()">
      <text>Tap to pulse</text>
    </view>
  `,
})
export class Pulse {
  readonly box = viewChild.required<ElementRef>('box');

  pulse(): void {
    this.box().nativeElement.animate(
      [
        { transform: 'scale(1)' },
        { transform: 'scale(1.2)' },
        { transform: 'scale(1)' },
      ],
      { duration: 300, easing: 'ease-out' },
    );
  }
}

Animate from code covers the options and how to pause or cancel.

Enter and leave

Give an element in an @if or @for Angular's animate.enter and animate.leave classes. See Enter and leave transitions.

Or wrap content in <lynx-transition> to animate it in when show turns true, and out before it's removed:

<lynx-transition [show]="visible()" name="fade" [duration]="300">
  <view class="panel">
    <text>I animate in and out</text>
  </view>
</lynx-transition>

The fade-enter and fade-leave classes each need a @keyframes animation. See Enter and leave with LynxTransition.

What can animate

Both transition and @keyframes animate only these properties:

GroupProperties
Positionleft, right, top, bottom
Sizewidth, height, min-width, max-width, min-height, max-height, flex-basis, flex-grow
Spacingpadding-top, padding-right, padding-bottom, padding-left, and the same four for margin
Bordersborder-top-width and the other three sides, border-top-color and the other three sides
Appearanceopacity, background-color, color, filter
Transformtransform, transform-origin

Any other property, such as border-radius, font-size or letter-spacing, doesn't animate.