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:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware match.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.
#1 Best Overall
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.
Rank #2
.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.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minute@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.
Rank #4
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.
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:
Best Value
@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.
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.
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.
Quick Recap
Sources
- Angular: Enter and Leave animations
- Angular: Complex Animations with CSS
- Angular: Complex Sequences
- Angular API: animate; query; keyframes
- Angular: Transition and Triggers
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.




