JavaScript Element getAnimations() Method

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline
Instance method

What You’ll Learn

Element.getAnimations() is an instance method from the Web Animations API. It returns an array of Animation objects affecting the element—CSS animations, transitions, and JavaScript animate() calls. Learn subtree and pseudoElement options, controlling playback, and five try-it labs.

01

Kind

Instance method

02

Returns

Animation[]

03

Includes

CSS + WAAPI

04

Options

subtree, pseudo

05

Control

pause, cancel, finished

06

Status

Baseline widely

Introduction

When you call animate(), the browser creates an Animation and starts playing it. But elements can also animate from CSS @keyframes, transition, or multiple overlapping effects.

getAnimations() gives you one array of every Animation currently targeting the element. From there you can pause(), cancel(), or await animation.finished before updating the DOM.

💡
Beginner tip

An empty array is normal when nothing is animating. Run getAnimations() after styles apply or after calling animate().

This page is part of JavaScript Element. Pair it with animate() for the full Web Animations workflow.

Understanding the getAnimations() Method

Calling el.getAnimations(options) queries the browser’s animation engine for effects tied to el. Each entry is a live Animation object you can control.

  • It is an instance method on Element.
  • Covers CSS animations, CSS transitions, and Web Animations.
  • Optional { subtree: true } includes descendant animations and pseudo-elements.
  • Optional { pseudoElement: "::after" } filters to one pseudo-element.
  • Returns an array—use .length, forEach, or map.
  • Invalid pseudoElement selectors throw an exception (MDN).

📝 Syntax

General forms of Element.getAnimations (MDN):

JavaScript
getAnimations()
getAnimations(options)

Parameters

  • options (optional) — an object with:
    • subtree — if true, include animations on descendants and their pseudo-elements. Default false.
    • pseudoElement — a string such as "::after" to target a pseudo-element.

Return value

An array of Animation objects targeting the element (per options).

Common patterns

JavaScript
const el = document.getElementById("box");

// List animations on this element only
const anims = el.getAnimations();
console.log(anims.length);

// Include descendants
const all = el.getAnimations({ subtree: true });

// Pause every animation on the element
el.getAnimations().forEach((a) => a.pause());

// Wait for all, then remove (MDN)
Promise.all(
  el.getAnimations({ subtree: true }).map((a) => a.finished)
).then(() => el.remove());

⚡ Quick Reference

GoalCode
Animations on elementel.getAnimations()
Include descendantsel.getAnimations({ subtree: true })
Pseudo-element onlyel.getAnimations({ pseudoElement: "::after" })
Pause allel.getAnimations().forEach(a => a.pause())
Await all finishedPromise.all(anims.map(a => a.finished))
MDN statusBaseline Widely available (since July 2020)

🔍 At a Glance

Four facts to remember about Element.getAnimations().

Returns
Animation[]

Array of effects

Baseline
widely

Since July 2020

Sources
CSS+JS

All animation types

subtree
optional

Include children

📋 getAnimations() vs animate() vs Document.getAnimations()

el.getAnimations()el.animate()document.getAnimations()
PurposeList existing animationsCreate and play new animationList all document animations
Return valueAnimation[]Single AnimationAnimation[]
ScopeOne element (+ options)One elementEntire document
Starts playbackNoYes (by default)No
Best forInspect / control effectsRun new keyframe animationGlobal animation manager

Examples Gallery

Examples follow MDN Element.getAnimations() patterns. Use View Output or Try It Yourself for each case.

📚 Getting Started

List animations after calling animate() or from CSS.

Example 1 — After animate()

Create a Web Animation, then read it back with getAnimations().

JavaScript
const box = document.getElementById("box");

box.animate(
  [{ transform: "translateX(0)" }, { transform: "translateX(100px)" }],
  { duration: 2000, fill: "forwards" }
);

const anims = box.getAnimations();
console.log(anims.length);        // 1
console.log(anims[0].playState);  // "running"
Try It Yourself

How It Works

animate() registers an effect on the element. getAnimations() returns the same live Animation objects the engine is running.

Example 2 — CSS @keyframes Animation

CSS-driven animations appear in the array too.

JavaScript
const box = document.getElementById("box");
// box has CSS: animation: pulse 2s infinite;

const anims = box.getAnimations();
console.log(anims.length >= 1);           // true
console.log(anims[0].effect.timing.duration); // 2000
Try It Yourself

How It Works

MDN notes the array includes CSS animations and transitions—not only JavaScript-created ones.

📈 Practical Patterns

subtree, await finished, and bulk control.

Example 3 — subtree: true (MDN)

Include animations on child elements when the parent itself has none.

JavaScript
const parent = document.getElementById("parent");
const child = document.getElementById("child");

child.animate([{ opacity: 1 }, { opacity: 0.5 }], { duration: 1000, iterations: Infinity });

console.log(parent.getAnimations().length);                  // 0
console.log(parent.getAnimations({ subtree: true }).length);   // 1
Try It Yourself

How It Works

By default only animations targeting the element count. With subtree: true, descendant effects are included (MDN).

Example 4 — Wait for All to Finish (MDN)

Remove an element only after every animation on it and its descendants completes.

JavaScript
const elem = document.getElementById("panel");

Promise.all(
  elem.getAnimations({ subtree: true }).map((animation) => animation.finished)
).then(() => {
  elem.remove();
  console.log("removed after animations");
});
Try It Yourself

How It Works

Each Animation has a finished promise. MDN uses Promise.all to coordinate cleanup across the subtree.

Example 5 — Pause Every Animation

Freeze all motion on an element with one loop.

JavaScript
const box = document.getElementById("box");
box.animate([{ transform: "scale(1)" }, { transform: "scale(1.2)" }], {
  duration: 800,
  iterations: Infinity,
  direction: "alternate"
});

box.getAnimations().forEach((a) => a.pause());

console.log(box.getAnimations()[0].playState);
// "paused"
Try It Yourself

How It Works

Because getAnimations() returns live objects, calling pause() on each one immediately stops playback.

🚀 Common Use Cases

  • Pausing UI motion when the user toggles “reduce motion”.
  • Waiting for exit animations before removing a modal or toast.
  • Debugging how many effects overlap on one element.
  • Coordinating CSS and JavaScript animations on the same node.
  • Targeting pseudo-element animations with pseudoElement (with fallbacks).
  • Building animation utilities that wrap animate() and getAnimations().

🧠 How getAnimations() Collects Effects

1

Call on an element

el.getAnimations(options) queries the animation engine.

Query
2

Apply options

subtree widens scope; pseudoElement narrows to a pseudo.

Filter
3

Gather Animation objects

CSS animations, transitions, and WAAPI effects are unified in one array.

Collect
4

Control or await

Use playState, pause(), cancel(), or finished on each entry.

📝 Notes

  • Not Deprecated, Experimental, or Non-standard on MDN (Baseline Widely available, July 2020).
  • Includes CSS animations, CSS transitions, and Web Animations (MDN).
  • Empty array means no matching animations at query time.
  • pseudoElement support varies—MDN shows a subtree filter fallback.
  • See also Document.getAnimations() for document-wide queries.
  • Related: animate(), computedStyleMap(), checkVisibility(), JavaScript hub.

Browser Support

Element.getAnimations() is Baseline Widely available (MDN: across browsers since July 2020). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline Widely available

Element.getAnimations()

List and control CSS and JavaScript animations on any element.

Baseline Widely available
Google Chrome Supported · Desktop & Mobile
Yes
Microsoft Edge Supported · Chromium
Yes
Mozilla Firefox Supported · Desktop & Mobile
Yes
Apple Safari Supported · macOS & iOS
Yes
Opera Supported · Modern versions
Yes
Internet Explorer Not supported
No
getAnimations() Excellent

Bottom line: Use getAnimations() to inspect or control effects after animate() or CSS animations. Use subtree when child animations matter, and Promise.all(animation.finished) before DOM cleanup.

Conclusion

Element.getAnimations() is how you discover every animation affecting an element—from CSS or JavaScript—and control them through the returned Animation objects.

Continue with animate(), shadowRoot, computedStyleMap(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Pair with animate() for create + inspect workflows
  • Use { subtree: true } when children animate
  • Await animation.finished before removing nodes
  • Respect prefers-reduced-motion by pausing effects
  • Handle empty arrays gracefully

❌ Don’t

  • Assume getAnimations() creates new animations
  • Forget pseudo-element fallback patterns on older engines
  • Call before styles or animate() have applied
  • Confuse with document.getAnimations() scope
  • Leave infinite animations running when not needed

Key Takeaways

Knowledge Unlocked

Five things to remember about Element.getAnimations()

List every animation on an element—then control them.

5
Core concepts
📄 02

Sources

CSS + WAAPI

Unified
✍️ 03

subtree

descendants

Option
04

Baseline

widely available

Status
05

finished

await cleanup

Pattern

❓ Frequently Asked Questions

It returns an array of Animation objects that currently affect the element (or are scheduled to). This includes CSS animations, CSS transitions, and Web Animations created with animate().
No. MDN marks Element.getAnimations() as Baseline Widely available (across browsers since July 2020). It is not Deprecated, Experimental, or Non-standard.
An array of Animation instances. An empty array means no animations are targeting the element with the options you passed.
Pass { subtree: true } to also include animations on descendant elements and their pseudo-elements. Defaults to false.
animate() creates and plays a new animation. getAnimations() lists animations already affecting the element so you can pause, cancel, or await animation.finished.
The document-level variant returns all animations in the document. Element.getAnimations() is scoped to one element (plus optional subtree).
Did you know?

MDN’s classic cleanup snippet uses Promise.all(elem.getAnimations({ subtree: true }).map(a => a.finished)) so you can remove a container only after every child animation completes—not just effects on the parent node itself.

More Element Topics

Browse Element methods and properties to keep building your DOM skills.

animate() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful