JavaScript Document getAnimations() Method

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

What You’ll Learn

document.getAnimations() is an instance method that returns every Animation currently in effect under the document (see MDN Document: getAnimations()). Learn what the array contains (CSS animations, transitions, and Web Animations), how to change playbackRate, pause or cancel everything, how it compares to Element.getAnimations(), and five try-it labs.

01

Kind

Instance method

02

Params

None

03

Returns

Animation[]

04

Includes

CSS + WAAPI

05

Scope

whole document

06

Status

Baseline

Introduction

Pages mix motion from many sources: CSS @keyframes, CSS transitions, and JavaScript element.animate(). The Web Animations API unifies them as Animation objects you can inspect and control.

MDN: document.getAnimations() returns an array of all Animation objects currently in effect whose targets are descendants of the document — including CSS Animations, CSS Transitions, and Web Animations.

💡
Think: a remote for every running animation

1) Call document.getAnimations()
2) Get an array of Animation objects
3) Loop to read playState or change playbackRate
4) Pause, play, or cancel as needed

Related tutorials: Element.getAnimations(), exitPointerLock(), parseHTML().

Understanding document.getAnimations()

An instance method on the page’s document object (also defined for ShadowRoot in the Web Animations spec; MDN Document page).

  • Parameters — none (MDN).
  • Return value — an Array of Animation objects (MDN).
  • Targets — animations whose target elements are descendants of this document (MDN).
  • Sources — CSS Animations, CSS Transitions, and Web Animations (MDN).
  • Empty array — nothing is currently animating under the document.
  • Scoped cousinelement.getAnimations() for one element (optional subtree).

📝 Syntax

General form of Document.getAnimations (MDN):

JavaScript
getAnimations()

Parameters

None (MDN).

Return value

An Array of Animation objects, each representing one animation currently associated with descendant elements of the Document (MDN).

MDN example (slow everything down)

JavaScript
document.getAnimations().forEach((animation) => {
  animation.playbackRate *= 0.5;
});

That snippet halves the speed of every current animation on the page by multiplying Animation.playbackRate by 0.5 (MDN).

⚡ Quick Reference

GoalCode
List alldocument.getAnimations()
Countdocument.getAnimations().length
Slow all (MDN)document.getAnimations().forEach(a => a.playbackRate *= 0.5)
Pause alldocument.getAnimations().forEach(a => a.pause())
Cancel alldocument.getAnimations().forEach(a => a.cancel())
One elementel.getAnimations() or el.getAnimations({ subtree: true })
MDN statusBaseline Widely available (since Sep 2020)

🔍 At a Glance

Four facts about document.getAnimations().

Returns
Animation[]

array

Params
none

MDN

Includes
CSS + WAAPI

transitions too

Status
Baseline

since 2020

📋 Useful Animation controls

Property / methodWhat it does
playbackRateSpeed multiplier (MDN sample halves it)
playStatee.g. running, paused, finished
pause() / play()Freeze or resume
cancel()Stop and clear the animation effect
finishedPromise that resolves when the animation finishes

Examples Gallery

Examples follow MDN Document: getAnimations() and practical Web Animations patterns for beginners.

📚 Getting Started

Read the document-wide animation list and change speed.

Example 1 — MDN: halve every playbackRate

Slow down all current animations on the page.

JavaScript
document.getAnimations().forEach((animation) => {
  animation.playbackRate *= 0.5;
});

console.log(
  document.getAnimations().map((a) => a.playbackRate)
);
Try It Yourself

How It Works

MDN’s one-liner walks every returned Animation and multiplies playbackRate. Values below 1 slow motion; above 1 speeds it up.

Example 2 — Count and inspect playState

Log how many animations are active and each play state.

JavaScript
const anims = document.getAnimations();
console.log("count:", anims.length);
console.log(
  anims.map((a) => a.playState).join(", ") || "(none)"
);
Try It Yourself

How It Works

An empty array means nothing is currently in effect under the document. After element.animate() or a CSS animation starts, length grows.

📈 Practical Patterns

Pause, cancel, and scope to one element.

Example 3 — Pause every animation

Handy for accessibility “reduce motion” toggles or debug freezes.

JavaScript
document.getAnimations().forEach((animation) => {
  animation.pause();
});

console.log(
  document.getAnimations().map((a) => a.playState).join(", ")
);
Try It Yourself

How It Works

pause() freezes each Animation in place. Call play() later to resume.

Example 4 — Cancel every animation

Stop and clear effects when leaving a page section.

JavaScript
document.getAnimations().forEach((animation) => {
  animation.cancel();
});

console.log("remaining:", document.getAnimations().length);
Try It Yourself

How It Works

After cancel(), those animations are no longer in effect, so a fresh getAnimations() call usually returns an empty array.

Example 5 — Document list vs one element

Compare whole-page count with a single element’s list.

JavaScript
const box = document.getElementById("box");
box.animate(
  [{ opacity: 1 }, { opacity: 0.3 }, { opacity: 1 }],
  { duration: 1500, iterations: Infinity }
);

console.log("document:", document.getAnimations().length);
console.log("element:", box.getAnimations().length);
Try It Yourself

How It Works

With only one animated node, both counts match. Add more animated elements and the document count grows while each element stays local — see Element.getAnimations().

🚀 Common Use Cases

  • Global slow-mo / speed-up — MDN’s playbackRate pattern.
  • Pause all motion — accessibility or debug overlays.
  • Cleanup — cancel leftover animations when unmounting a view.
  • Diagnostics — count running animations during performance work.
  • Prefer element scope — use Element.getAnimations() for a single widget.
  • Not creating motion — use element.animate() or CSS to start animations.

🧠 How getAnimations() Works

1

Animations are already running

From CSS, transitions, or element.animate() on document descendants.

Sources
2

Call document.getAnimations()

No arguments. The browser collects in-effect Animation objects (MDN).

Query
3

Receive an array

Each entry is a live Animation you can inspect or control.

Result
4

Loop and control

Change playbackRate, pause, play, cancel, or await finished.

📝 Notes

Browser Support

Document.getAnimations() is Baseline Widely available on MDN (since September 2020). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline Widely available

Document.getAnimations()

List every in-effect Animation under the document — CSS, transitions, and Web Animations.

Baseline Widely available
Google Chrome Supported
Yes
Mozilla Firefox Supported
Yes
Apple Safari Supported
Yes
Microsoft Edge Supported
Yes
Opera Supported
Yes
Internet Explorer Not supported
No
getAnimations() Wide

Bottom line: Use document.getAnimations() for page-wide control. Prefer Element.getAnimations() when you only need one element or subtree.

Conclusion

document.getAnimations() is your document-wide inventory of live Animation objects. Use it to slow, pause, or cancel motion across the page — exactly the toolkit MDN demonstrates with playbackRate.

Continue with Element.getAnimations(), getElementById(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use document scope for global pause / slow-mo tools
  • Prefer Element.getAnimations() for a single component
  • Re-call getAnimations() after starting or canceling motion
  • Respect prefers-reduced-motion when pausing page animations
  • Inspect playState and playbackRate while debugging

❌ Don’t

  • Expect parameters on Document.getAnimations() (MDN: none)
  • Assume an empty array means animations never existed — they may have finished
  • Cancel everything if you only meant to pause one widget
  • Forget IE lacks this API (prefer modern Baseline browsers)
  • Confuse listing animations with creating them (animate() / CSS)

Key Takeaways

Knowledge Unlocked

Five things to remember about getAnimations()

List every live Animation under the document, then control them.

5
Core concepts
🔄02

Includes

CSS + WAAPI

transitions
03

MDN tip

playbackRate

slow / speed
📄04

Scoped alt

Element.getAnimations

local
🛡05

Status

Baseline

2020

❓ Frequently Asked Questions

MDN: Document.getAnimations() returns an array of all Animation objects currently in effect whose target elements are descendants of the document. This includes CSS Animations, CSS Transitions, and Web Animations.
No. MDN marks Document.getAnimations() as Baseline Widely available (since September 2020). It is not Deprecated, Experimental, or Non-standard.
An Array of Animation objects, each representing one animation currently associated with descendant elements of the Document (MDN).
No. MDN: Document.getAnimations() has no parameters. (Element.getAnimations() can take an options object such as subtree.)
Document.getAnimations() lists animations across the whole document. Element.getAnimations() is scoped to one element (optionally including its subtree).
Common controls include playbackRate, play(), pause(), cancel(), and awaiting animation.finished. MDN’s example halves every animation’s playbackRate.
Did you know?

The same getAnimations() idea exists on ShadowRoot in the Web Animations specification — so encapsulated components can inventory their own animations without scanning the whole page.

Next: getElementById()

Learn the classic Document method for finding an element by its unique id.

getElementById() →

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.

6 people found this page helpful