@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
AddBrowserAnimationsModule 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: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: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:query()
Query child elements to animate them:.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
UseAnimationBuilder 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 motionQuery options
Use
{ optional: true } in queries to prevent errors when elements don’t existClean up
Animations clean up automatically, but call
destroy() on manual playersDisable Animations
Respect User Preferences
API Reference
Core Functions
trigger()
trigger()
Creates a named animation trigger
state()
state()
Defines a named state with styles
transition()
transition()
Defines a transition between states
style()
style()
Defines styles for an animation state
animate()
animate()
Defines timing and styles for animation
Composition Functions
sequence()
sequence()
Runs animation steps sequentially
group()
group()
Runs animation steps in parallel
keyframes()
keyframes()
Defines keyframe-based animation
query()
query()
Queries child elements for animation
stagger()
stagger()
Staggers animations across multiple elements
animateChild()
animateChild()
Triggers child animations
Reusable Animations
animation()
animation()
Defines a reusable animation
useAnimation()
useAnimation()
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
