October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Angular CSS Animations: How to Compose Complex Motion

Compose complex Angular animations in CSS, then use animate.enter and animate.leave to connect effects to DOM insertion and removal.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For new Angular code, build motion with CSS transitions and @keyframes, then connect DOM insertion and removal to animate.enter and animate.leave. Angular’s documentation recommends native CSS with these APIs for all new animation code. The CSS defines how motion looks; Angular recognizes when a node enters or leaves and manages the classes and element lifetime.

Choose a CSS technique for the motion

Use a transition when an element moves between two style states, such as a panel changing from hidden to visible. Use @keyframes when motion needs explicit intermediate steps, or when you want to reuse a multi-step sequence. Both can be used with Angular’s entry and exit APIs.

As an Amazon Associate I earn from qualifying purchases.

Transition between two states

For an entering panel, the base rule describes its resting state. The class supplied to animate.enter describes its destination. Add @starting-style to provide the initial state for the transition:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.panel {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 240ms ease-out, transform 240ms ease-out;
}

.panel-enter {
  opacity: 1;
  transform: translateY(0);
}

@starting-style {
  .panel-enter {
    opacity: 0;
    transform: translateY(12px);
  }
}

The starting style supplies the before-state; the class and base styling establish the destination. Choose a duration and easing that suit the interface rather than treating example timings as a universal rule.

Use keyframes for intermediate steps

A keyframe animation describes its own stages, so it is a better fit when the motion has an arc that cannot be expressed as a simple transition between two states:

@keyframes card-arrive {
  0% {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  70% {
    opacity: 1;
    transform: translateY(-3px) scale(1);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

.card-enter {
  animation: card-arrive 360ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

Use animation-duration, animation-delay, and animation-timing-function (or their shorthand equivalents) to control how long the effect runs, when it begins, and how its pace changes. Transitions have corresponding duration, delay, and timing-function properties.

Compose staggered and simultaneous effects

Stagger a list with per-item delays

For a cascade, assign each item a progressively larger animation delay. Angular’s CSS guidance demonstrates this delay-based approach; the delay is ordinary CSS rather than an Angular sequencing instruction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.item-enter {
  animation: card-arrive 360ms ease-out both;
}

.item-enter:nth-child(2) { animation-delay: 60ms; }
.item-enter:nth-child(3) { animation-delay: 120ms; }
.item-enter:nth-child(4) { animation-delay: 180ms; }

For dynamic collections, arrange for each rendered item to receive the appropriate delay—for example, through a class or a CSS custom property based on its index. Keep the number of delayed items and total cascade time appropriate to the interface.

Run multiple effects in parallel

To combine independent keyframe effects, list them in one animation declaration. Comma-separated animations run at the same time unless their delays or other settings specify otherwise:

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-up {
  from { transform: translateY(12px); }
  to { transform: translateY(0); }
}

.dialog-enter {
  animation: fade-in 220ms ease-out both,
             slide-up 300ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

When you need to inspect or control animations while they run, Element.getAnimations() can return animations associated with an element. The Web Animations API can then pause, play, reverse, or cancel them.

Connect CSS to Angular’s entry and exit lifecycle

animate.enter and animate.leave are compiler-supported APIs, not directives. Put them on the element whose DOM insertion or removal should trigger motion. They accept a CSS class name or an array of class names; the classes can select transitions or keyframe animations.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
@if (isOpen) {
  <section class="panel"
           animate.enter="panel-enter"
           animate.leave="panel-leave">
    <h2>Details</h2>
    <p>Content for the panel.</p>
  </section>
}

In a component template, write the HTML elements normally; the escaped angle brackets above represent markup inside the code example.

What happens on entry

When Angular inserts the element, it applies the entry class or classes. Angular removes those temporary classes when the associated animation or transition finishes. With multiple animations or transitions, Angular waits for the longest one. For transition-based entry, pair the enter class with @starting-style when the browser needs an explicit initial state; the base element CSS describes the resting style.

What happens on leave

When Angular removes the element, it applies the leave class or classes and keeps the element in the DOM until the leave animation finishes. If multiple animations apply, the longest determines when Angular removes the node. This lets the exit motion complete before the element disappears.

The APIs can also be used as host bindings. Use that option when the component host itself is the element whose entry or exit should be animated.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Account for accessibility and component boundaries

Respect reduced-motion preferences

Some users ask their operating system or browser to reduce motion. Use the prefers-reduced-motion media query to reduce or remove nonessential movement while preserving clear state changes:

@media (prefers-reduced-motion: reduce) {
  .panel,
  .panel-enter,
  .panel-leave {
    animation-duration: 1ms;
    transition-duration: 1ms;
  }
}

Apply the preference to the actual selectors and motion effects used by the interface; avoid replacing motion with an abrupt change if a short, restrained transition still communicates the state.

Do not assume nested leave animations will run

Angular’s CSS animation guide warns that nested component animate.leave animations do not fire when a parent element is removed. If a parent leaves, do not rely on every descendant component receiving its own independent leave lifecycle. Put the required exit effect on the element Angular is removing, or structure the DOM so the element that needs a separate exit can remain under Angular’s control.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use legacy Angular animations for maintenance, not as the default for new code

Angular’s “Complex Sequences” documentation states: “The Angular team recommends using native CSS with animate.enter and animate.leave for animations for all new code.” Existing applications may still contain the older @angular/animations trigger and transition model, including state-based examples documented under “Transition and Triggers.”

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The legacy vocabulary remains useful when maintaining or migrating those applications: query() selects descendants, stagger() adds cascading delays, group() runs steps in parallel, and sequence() runs them in order. These are legacy animation metadata tools, distinct from CSS delays and animation declarations.

Angular’s API references mark animate, query, and keyframes deprecated since v20.2. The keyframes API reference states an intent to remove it in v23; that is a stated future intent, not evidence that removal has already occurred. Check the current API references when planning an upgrade, and avoid introducing the legacy package in new work without a specific migration or compatibility reason.

Sources

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.