Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober 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 Now×
Skip to content
World desk4 min

Angular Animation Triggers and Transitions: How They Work and What to Use Now

Angular triggers group animation states and transitions. Learn how matching works, when wildcards apply, and how to approach new CSS-based animations.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An Angular animation trigger is a named group of state and transition rules, attached to a template element through a binding. A transition decides when animation steps run as the bound value changes. The legacy @angular/animations APIs are deprecated since Angular v20.2, and Angular says it intends to remove them in v23; for new enter-and-leave effects, the framework recommends CSS with animate.enter and animate.leave.

How triggers, states, and transitions fit together

A trigger defines the animation behavior for an element. It groups named states and transition rules, then a template binding supplies the value that Angular watches. Angular converts that bound value to a string when matching it against declared states.

As an Amazon Associate I earn from qualifying purchases.

trigger('panelMotion', [
  state('open', style({ opacity: 1 })),
  state('closed', style({ opacity: 0 })),
  transition('open => closed', animate('200ms')),
  transition('closed => open', animate('200ms')),
])

In a template, bind the trigger with its name prefixed by @:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<section [@panelMotion]="panelState">...</section>

Here, panelState supplies values such as open and closed. A state() declaration associates a state name with styles; once that state is reached, its styles remain on the element. A transition() declaration provides animation instructions when a matching change occurs. See Angular’s trigger API and state API.

Which transition expressions match a change?

A transition expression describes the state change it accepts. The transition rules are evaluated in declaration order, so put narrow matches before a catch-all rule.

Expression What it matches When it is useful
open => closed A change from open to closed only. When the two directions need different animation steps.
open <=> closed Changes in either direction between those two states. When both directions share the same transition instructions.
* => * Any change from one state to another. As a general fallback after more specific rules.
:enter or :leave An element entering or leaving the view. For legacy trigger-based effects tied to view insertion or removal.
:increment or :decrement A numeric value increasing or decreasing. When an animation responds to a numeric change.

The wildcard state * matches any state, while void represents an element detached from the application. A transition matcher can also be a function for custom matching logic. The Angular transition and trigger guide documents the legacy matching syntax.

Order specific rules before a wildcard fallback

Because rules are matched in order, a broad * => * declaration can catch a change before a later, more specific declaration gets a chance to handle it. Put explicit state-pair rules first and the catch-all last.

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

How to animate elements entering or leaving

For new code, use Angular’s compiler-supported animate.enter and animate.leave APIs. They apply CSS classes at the relevant point in an element’s lifecycle, or can call functions for integrations with third-party animation systems. The framework’s enter and leave guide provides the current approach.

For many effects, a class change plus CSS is enough. CSS transitions interpolate between styles, while CSS keyframes describe a sequence of intermediate styles. Angular’s CSS animation guide explains handling state changes by toggling classes and styling those classes with transitions or keyframes.

How to choose an approach for a new or existing animation

  • New enter-or-leave effect: Use animate.enter or animate.leave with CSS classes, following Angular’s current guidance.
  • Existing trigger with state-dependent styling: Identify the states, the styles that must persist at the end, and the transitions between them. Recreate that behavior with class changes and CSS where appropriate.
  • Simple change between visual states: A CSS transition is often suitable when the effect is an interpolation between start and end styles.
  • Several timed stages: CSS keyframes can express a sequence of intermediate styles.
  • Complex sequences or nested legacy triggers: Review the exact behavior before migrating. Angular’s documentation does not prescribe one automatic, universal conversion for every legacy animation.

The choice depends on whether an effect follows DOM insertion or removal, whether end-state styles must persist, and how much sequencing or nesting it requires. Retaining legacy syntax may be necessary while maintaining existing code, but it is not Angular’s recommended direction for new animations.

What happens with nested legacy triggers?

A parent legacy animation takes priority and blocks animations on child elements unless the parent explicitly queries those child elements and invokes animateChild(). This matters when a child has its own trigger: the child animation may not run merely because its state changes while the parent animation is active. The legacy guide also covers start and done callbacks and keyframe sequences.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Are Angular animation triggers deprecated?

Yes. Angular marks the legacy @angular/animations APIs as deprecated since v20.2. The transition() API reference says to use animate.enter or animate.leave instead and records an intent to remove the API in v23. Angular’s legacy guide likewise recommends native CSS with those APIs for all new code. Because the stated removal plan is version-sensitive, check the current transition API reference when planning an upgrade.

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
Windows Errors? Fix Them Before They SpreadFree repair scan

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.