Start with Plain CSS
Many effects need no Angular code at all. Use CSS transitions with a class toggle.
html
<button (click)="open.set(!open())">Toggle</button>
<div class="panel" [class.open]="open()">Content</div>
css
.panel { max-height: 0; opacity: 0; overflow: hidden; transition: all 250ms ease; }
.panel.open { max-height: 300px; opacity: 1; }
animate.enter and animate.leave
Newer Angular versions add animate.enter and animate.leave so you can animate elements as they are added to and removed from the page, using ordinary CSS classes.
Version note: This feature was introduced in Angular 20.2 as the modern replacement for the older animations package. Check angular.dev for the details of your version.
html
@if (visible()) {
<div class="card" animate.enter="fade-in" animate.leave="fade-out">Hello</div>
}
css
.fade-in { animation: fadeIn 300ms ease forwards; }
.fade-out { animation: fadeOut 200ms ease forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-8px); } }
Angular waits for the leave animation to finish before it removes the element. It also works with @for items.
The Animations Package (Existing Projects)
Many projects still use @angular/animations. You will see it in older code and in some libraries.
typescript
import { trigger, state, style, transition, animate } from '@angular/animations';
@Component({
selector: 'app-box',
animations: [
trigger('openClose', [
state('open', style({ height: '200px', opacity: 1 })),
state('closed', style({ height: '0', opacity: 0 })),
transition('open <=> closed', animate('300ms ease-in-out')),
]),
trigger('listAnim', [
transition(':enter', [style({ opacity: 0, transform: 'translateX(-20px)' }), animate('250ms', style({ opacity: 1, transform: 'none' }))]),
transition(':leave', [animate('200ms', style({ opacity: 0 }))]),
]),
],
template: `
<div [@openClose]="isOpen() ? 'open' : 'closed'">Panel</div>
@for (i of items(); track i.id) { <p @listAnim>{{ i.name }}</p> }
`,
})
export class Box { isOpen = signal(true); items = signal<Item[]>([]); }
typescript
// app.config.ts
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
providers: [provideAnimationsAsync()]
Route Transitions (Idea)
css
::view-transition-old(root) { animation: fadeOut 150ms ease; }
::view-transition-new(root) { animation: fadeIn 250ms ease; }
typescript
provideRouter(routes, withViewTransitions()) // browser View Transitions API
Respect Reduced Motion
css
@media (prefers-reduced-motion: reduce) {
* { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
Keep it subtle: Use animation to explain a change (an item appeared, a panel opened), not to decorate. Short durations between 150 and 300 ms feel natural.
Conclusion
Use CSS first, animate.enter and animate.leave for elements entering and leaving, and the animations package when maintaining older code. Always respect reduced-motion settings.
Quick Summary: CSS transitions + animate.enter/leave; @angular/animations in legacy code.