Skip to main content

Overview

Angular’s animation system provides a powerful DSL (Domain Specific Language) for creating complex animations and transitions. Built on top of the Web Animations API, it offers declarative syntax for common animation patterns.

Setup

Import the animations module to enable animation support.

Standalone Application

NgModule Application

Basic Animations

Simple Trigger

Create basic animations using triggers and states.

Wildcard States

Use wildcards for flexible state matching.

Enter and Leave Animations

Animate elements as they enter or leave the DOM.
Use :enter and :leave aliases for the special void => * and * => void transitions.

Advanced Animations

Keyframes

Create complex multi-step animations.

Parallel Animations

Run multiple animations simultaneously using group().

Sequential Animations

Chain animations using sequence().

Stagger Animations

Animate list items with a stagger effect.

Route Animations

Animate transitions between routes.

Animation Callbacks

Listen to animation events.

Reusable Animations

Create reusable animation definitions.

Best Practices

Use Hardware Acceleration

Animate transform and opacity for better performance.

Provide Animation Metadata

Use the optional flag in queries for flexible animations.

Disable in Tests

Use provideNoopAnimations() in tests for faster execution.

Reuse Definitions

Create reusable animations with animation() and useAnimation().
Avoid animating properties like width, height, or left directly as they trigger layout recalculation. Use transform: scale() and transform: translate() instead.

Additional Resources