Skip to main content

Overview

Svelte Atoms Core provides powerful animation lifecycle hooks that work seamlessly with third-party animation libraries like GSAP, Motion One, and anime.js. Every atom exposes hooks for initial state, enter/exit transitions, and data-driven animations.
All animation hooks expose the host element, making it easy to integrate with any animation library of your choice.

Animation Hooks API

Every atom component supports these animation lifecycle hooks:

Hook Execution Order

  1. initial: Called before the element enters the DOM
  2. enter: Called when the element enters the DOM
  3. animate: Called when reactive data changes (after enter completes)
  4. exit: Called when the element exits the DOM

Using Animation Hooks

Basic Enter/Exit Transitions

Use Svelte’s built-in transitions:

Initial State Setup

Set the initial appearance before the enter animation:

Data-Driven Animations

Use the animate hook to respond to state changes:

Integration with Animation Libraries

Motion One

Motion One provides a modern, performant animation API:
The toTransitionConfig utility converts animation library instances to Svelte’s TransitionConfig format.

GSAP

GSAP is the industry-standard animation library:

Anime.js

Real-World Examples

Accordion with Smooth Transitions

Toast Notifications

List with Stagger Animation

Page Transitions

Advanced Patterns

Conditional Animations

Animate differently based on conditions:

Respecting Reduced Motion

Cleanup and Cancellation

Animation Best Practices

Most UI animations should be between 200-400ms. Longer animations feel sluggish.
  • Ease-out: For elements entering (starts fast, ends slow)
  • Ease-in: For elements exiting (starts slow, ends fast)
  • Ease-in-out: For elements moving between states
Always check for prefers-reduced-motion and provide instant or minimal animations for users who need them.
Prefer animating transform and opacity over properties like width, height, or top.
Avoid animating too many elements simultaneously. This can cause performance issues, especially on lower-end devices.

Next Steps

Composition

Learn component composition patterns

Styling

Explore styling approaches

Components

Browse all animatable components

Motion One Docs

Read the Motion One documentation