Skip to main content

@angular/animations

The Angular animations package provides a powerful, declarative API for creating sophisticated animations in your Angular applications. Built on top of the Web Animations API, it offers fine-grained control over timing, styles, and complex animation sequences.

Overview

Angular animations enable you to define how HTML elements move, change appearance, and transition between states. The animation system integrates seamlessly with Angular’s component model and change detection.
Web Standards BasedAngular animations are built on the Web Animations API, providing high-performance animations that run efficiently in modern browsers.

Installation

Quick Start

1. Import the Module

Add BrowserAnimationsModule to your application:
app.config.ts

2. Define an Animation

Create animation triggers in your component:
example.component.ts

3. Bind to Template

Attach animations using the [@triggerName] syntax:

Core Concepts

Animation Triggers

Triggers define named animations that can be bound to elements:
function
Creates a named animation trigger

States

Define the appearance of an element in different states:
Use the wildcard state * to match any state, or void to represent an element entering or leaving the DOM.

Transitions

Define how elements animate between states:

Styles

Define CSS properties for animation states:
Use '*' or the special AUTO_STYLE constant to let Angular compute the value automatically.

Animation Functions

animate()

Specifies timing and styles for an animation step:
Timing Format: duration delay easing
  • duration: Time in ms or s (e.g., '300ms', '0.3s')
  • delay: Optional delay before starting
  • easing: Easing function (ease, ease-in, ease-out, ease-in-out, linear, cubic-bezier(...))

sequence()

Runs animation steps one after another:

group()

Runs animation steps in parallel:

keyframes()

Define animation keyframes for more complex sequences:
The offset property (0 to 1) specifies when each keyframe occurs during the animation.

query()

Query child elements to animate them:
Query Selectors:
  • .className - Elements with class
  • #id - Element with ID
  • :enter - Elements entering the DOM
  • :leave - Elements leaving the DOM
  • :animating - Currently animating elements
  • @triggerName - Elements with trigger
  • * - All elements

stagger()

Create staggered animations for lists:

animateChild()

Trigger child animations explicitly:

Common Animation Patterns

Fade In/Out

Slide In/Out

Scale/Zoom

Rotate

List Animations

Advanced Features

Reusable Animations

Create reusable animation definitions:
animations.ts

Animation Callbacks

Listen to animation events:
interface
Animation lifecycle event

Animation Parameters

Pass parameters to animations:

Programmatic Animations

Use AnimationBuilder for runtime control:
service
Programmatic animation builder
interface
Controls animation playback

Route Animations

Animate navigation between routes:
route-animations.ts
app.component.ts

Performance Optimization

Use transform & opacity

Animate transform and opacity for GPU acceleration. Avoid animating width, height, top, or left.

Disable animations

Use NoopAnimationsModule in tests or for users who prefer reduced motion

Query options

Use { optional: true } in queries to prevent errors when elements don’t exist

Clean up

Animations clean up automatically, but call destroy() on manual players

Disable Animations

Respect User Preferences

API Reference

Core Functions

Creates a named animation trigger
Defines a named state with styles
Defines a transition between states
Defines styles for an animation state
Defines timing and styles for animation

Composition Functions

Runs animation steps sequentially
Runs animation steps in parallel
Defines keyframe-based animation
Queries child elements for animation
Staggers animations across multiple elements
Triggers child animations

Reusable Animations

Defines a reusable animation
Uses a reusable animation

Constants

const
Automatically compute style values

Examples

Complete Component Example

Browser Support

Angular animations use the Web Animations API. For older browsers, you may need to include a polyfill.

Polyfill Installation

polyfills.ts

Resources

Animations Guide

Complete guide to Angular animations

Web Animations API

MDN Web Animations documentation

Animation Examples

Interactive examples and demos

Performance Tips

Web animation performance guide

Start SimpleBegin with basic fade and slide animations, then progressively add complexity as needed. Most UI animations should be subtle and fast (200-400ms).