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
Fundamentals
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().
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).
Foundation
📝 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());
Cheat Sheet
⚡ Quick Reference
Goal
Code
Animations on element
el.getAnimations()
Include descendants
el.getAnimations({ subtree: true })
Pseudo-element only
el.getAnimations({ pseudoElement: "::after" })
Pause all
el.getAnimations().forEach(a => a.pause())
Await all finished
Promise.all(anims.map(a => a.finished))
MDN status
Baseline Widely available (since July 2020)
Snapshot
🔍 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
Compare
📋 getAnimations() vs animate() vs Document.getAnimations()
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.
BaselineWidely available
Google ChromeSupported · Desktop & Mobile
Yes
Microsoft EdgeSupported · Chromium
Yes
Mozilla FirefoxSupported · Desktop & Mobile
Yes
Apple SafariSupported · macOS & iOS
Yes
OperaSupported · Modern versions
Yes
Internet ExplorerNot 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.
Wrap Up
Conclusion
Element.getAnimations() is how you discover every animation affecting an element—from CSS or JavaScript—and control them through the returned Animation objects.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Element.getAnimations()
List every animation on an element—then control them.
5
Core concepts
📝01
Returns
Animation[]
API
📄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.