Animation & Motion
Overview
Motion communicates change, hierarchy, and continuity when used purposefully; the Web Animations API (WAAPI) is the standard scriptable way to create and control animations in JavaScript. MDN documents the API; Material Design 3 motion guidance supplies the principles (easing, duration, transitions). Read this when adding animated feedback, page/element transitions, or coordinated motion.
Official sources
Core concepts
- Element.animate() — shortcut that creates and plays an animation on an element and returns an
Animation object (MDN WAAPI).
- KeyframeEffect — describes the animatable properties/values (keyframes) plus timing options (MDN WAAPI).
- Animation — object exposing playback controls (play, pause, reverse, finish) and a timeline (MDN WAAPI).
- AnimationTimeline / DocumentTimeline — the time source;
document.timeline is the default (MDN WAAPI).
- Element.getAnimations() / Document.getAnimations() — enumerate animations affecting an element or document (MDN WAAPI).
- Easing and duration — motion tokens that define acceleration curves and timing for consistent, natural movement (M3 easing and duration).
Best practices
- Use
Element.animate() for imperative, controllable animations and getAnimations() to coordinate or cancel them (MDN WAAPI).
- Apply system easing/duration tokens so motion is consistent across the product rather than ad-hoc per component (M3 easing and duration).
- Animate compositor-friendly properties (transform, opacity) for smooth, performant motion.
- Make motion purposeful — reinforce a state change or spatial relationship, not decoration (M3 motion overview).
Common pitfalls
- Long or non-interruptible animations that block the user → keep durations short and let
Animation controls pause/reverse (MDN WAAPI; M3 duration).
- Inconsistent easing per component → centralize on shared easing/duration tokens (M3 easing and duration).
- Ignoring reduced-motion users → respect
prefers-reduced-motion and scale back non-essential animation.
Examples
// WAAPI: fade + slide in, then control playback
const anim = card.animate(
[{ opacity: 0, transform: 'translateY(8px)' }, { opacity: 1, transform: 'none' }],
{ duration: 200, easing: 'cubic-bezier(0.2, 0, 0, 1)', fill: 'both' }
);
anim.onfinish = () => card.classList.add('is-ready');
// Respect user preference
if (matchMedia('(prefers-reduced-motion: reduce)').matches) anim.finish();
Further reading
Related skills
- ../microinteractions — small animated feedback cues built on these APIs
- ../css-techniques — transitions and keyframes as a declarative alternative
1---2name: animation-motion3description: Motion design principles and the Web Animations API for purposeful, performant UI animation; consult when adding transitions or animated feedback.4domain: design5category: design6tags: [animation, motion, web-animations-api, easing, transitions]7official_sources:8 - https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API9 - https://m3.material.io/styles/motion/overview10verified: 2026-06-1611metadata:12 source: https://skillmd.com/skills/gabriel7silva/animation-motion13---1415# Animation & Motion1617## Overview18Motion communicates change, hierarchy, and continuity when used purposefully; the Web Animations API (WAAPI) is the standard scriptable way to create and control animations in JavaScript. MDN documents the API; Material Design 3 motion guidance supplies the principles (easing, duration, transitions). Read this when adding animated feedback, page/element transitions, or coordinated motion.1920## Official sources21- MDN — Web Animations API: https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API22- Material Design 3 — Motion overview: https://m3.material.io/styles/motion/overview23- Material Design 3 — Easing and duration: https://m3.material.io/styles/motion/easing-and-duration/tokens-specs2425## Core concepts26- **Element.animate()** — shortcut that creates and plays an animation on an element and returns an `Animation` object (MDN WAAPI).27- **KeyframeEffect** — describes the animatable properties/values (keyframes) plus timing options (MDN WAAPI).28- **Animation** — object exposing playback controls (play, pause, reverse, finish) and a timeline (MDN WAAPI).29- **AnimationTimeline / DocumentTimeline** — the time source; `document.timeline` is the default (MDN WAAPI).30- **Element.getAnimations() / Document.getAnimations()** — enumerate animations affecting an element or document (MDN WAAPI).31- **Easing and duration** — motion tokens that define acceleration curves and timing for consistent, natural movement (M3 easing and duration).3233## Best practices34- Use `Element.animate()` for imperative, controllable animations and `getAnimations()` to coordinate or cancel them (MDN WAAPI).35- Apply system easing/duration tokens so motion is consistent across the product rather than ad-hoc per component (M3 easing and duration).36- Animate compositor-friendly properties (transform, opacity) for smooth, performant motion.37- Make motion purposeful — reinforce a state change or spatial relationship, not decoration (M3 motion overview).3839## Common pitfalls40- Long or non-interruptible animations that block the user → keep durations short and let `Animation` controls pause/reverse (MDN WAAPI; M3 duration).41- Inconsistent easing per component → centralize on shared easing/duration tokens (M3 easing and duration).42- Ignoring reduced-motion users → respect `prefers-reduced-motion` and scale back non-essential animation.4344## Examples45```js46// WAAPI: fade + slide in, then control playback47const anim = card.animate(48 [{ opacity: 0, transform: 'translateY(8px)' }, { opacity: 1, transform: 'none' }],49 { duration: 200, easing: 'cubic-bezier(0.2, 0, 0, 1)', fill: 'both' }50);51anim.onfinish = () => card.classList.add('is-ready');52// Respect user preference53if (matchMedia('(prefers-reduced-motion: reduce)').matches) anim.finish();54```5556## Further reading57- MDN WAAPI guides and interfaces: https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API58- M3 motion specs and tokens: https://m3.material.io/styles/motion/overview5960## Related skills61- ../microinteractions — small animated feedback cues built on these APIs62- ../css-techniques — transitions and keyframes as a declarative alternative