Web animations
The Animation interface of the Web Animations API represents a single animation player and provides playback controls and a timeline for an animation node or source.
EventTarget Animation
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 75 | 79 | 48 | 13.1 | 75 | 13.4 | |
| The Animation() constructor of the Web Animations API returns a new Animation object instance. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The Web Animations API's cancel() method of the Animation interface clears all KeyframeEffects caused by this animation and aborts its playback. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The cancel event of the Animation interface is fired when the Animation.cancel() method is called or when the animation enters the "idle" play state from another state, such as when the animation is removed from an element before it finishes playing. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The commitStyles() method of the Web Animations API's Animation interface writes the computed values of the animation's current styles into its target element's style attribute. | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
| The Animation.currentTime property of the Web Animations API returns and sets the current time value of the animation in milliseconds, whether running or paused. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The Animation.effect property of the Web Animations API gets and sets the target effect of an animation. The target effect may be either an effect object of a type based on AnimationEffect, such as KeyframeEffect, or null. | 75 | 79 | 63 | 13.1 | 75 | 13.4 |
| The finish() method of the Web Animations API's Animation Interface sets the current playback time to the end of the animation corresponding to the current playback direction. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The finish event of the Animation interface is fired when the animation finishes playing, either when the animation completes naturally, or when the Animation.finish() method is called to immediately cause the animation to finish up. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The Animation.finished read-only property of the Web Animations API returns a Promise which resolves once the animation has finished playing. | 84 | 84 | 63 | 13.1 | 84 | 13.4 |
| The Animation.id property of the Web Animations API returns or sets a string used to identify the animation. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The pause() method of the Web Animations API's Animation interface suspends playback of the animation. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The read-only Animation.pending property of the Web Animations API indicates whether the animation is currently waiting for an asynchronous operation such as initiating playback or pausing a running animation. | 76 | 79 | 59 | 13.1 | 76 | 13.4 |
| The persist() method of the Web Animations API's Animation interface explicitly persists an animation, preventing it from being automatically removed when it is replaced by another animation. | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
| The play() method of the Web Animations API's Interface starts or resumes playing of an animation. If the animation is finished, calling play() restarts the animation, playing it from the beginning. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The Animation.playbackRate property of the Web Animations API returns or sets the playback rate of the animation. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The read-only Animation.playState property of the Web Animations API returns an enumerated value describing the playback state of an animation. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The read-only Animation.ready property of the Web Animations API returns a Promise which resolves when the animation is ready to play. A new promise is created every time the animation enters the "pending" play state as well as when the animation is canceled, since in both of those scenarios, the animation is ready to be started again. | 84 | 84 | 63 | 13.1 | 84 | 13.4 |
| The remove event of the Animation interface fires when the animation is automatically removed by the browser. | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
| It is possible to trigger a large number of animations on the same element. If they are indefinite (i.e., forwards-filling), this can result in a huge animations list, which could create a memory leak. For this reason, browsers automatically remove filling animations after they are replaced by newer animations, unless the developer explicitly specifies to… | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
| The read-only Animation.replaceState property of the Web Animations API indicates whether the animation has been removed by the browser automatically after being replaced by another animation. | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
| The Animation.reverse() method of the Interface reverses the playback direction, meaning the animation ends at its beginning. If called on an unplayed animation, the whole animation is played backwards. If called on a paused animation, the animation will continue in reverse. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The Animation.startTime property of the Animation interface is a double-precision floating-point value which indicates the scheduled time when an animation's playback should begin. | 75 | 79 | 48 | 13.1 | 75 | 13.4 |
| The Animation.timeline property of the Animation interface returns or sets the AnimationTimeline associated with this animation. A timeline is a source of time values for synchronization purposes, and is an AnimationTimeline-based object. By default, the animation's timeline and the Document's timeline are the same. | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
| The updatePlaybackRate() method of the Web Animations API's Animation Interface sets the speed of an animation after first synchronizing its playback position. | 76 | 79 | 60 | 13.1 | 76 | 13.4 |
| The AnimationEffect interface of the Web Animations API is an interface representing animation effects. | 75 | 79 | 63 | 13.1 | 75 | 13.4 |
| The getComputedTiming() method of the AnimationEffect interface returns the calculated timing properties for this animation effect. | 75 | 79 | 63 | 13.1 | 75 | 13.4 |
| The AnimationEffect.getTiming() method of the AnimationEffect interface returns an object containing the timing properties for the Animation Effect. | 75 | 79 | 63 | 13.1 | 75 | 13.4 |
| The updateTiming() method of the AnimationEffect interface updates the specified timing properties for an animation effect. | 75 | 79 | 63 | 13.1 | 75 | 13.4 |
| The AnimationPlaybackEvent interface of the Web Animations API represents animation events. | 84 | 84 | 63 | 13.1 | 84 | 13.4 |
| The AnimationPlaybackEvent() constructor of the Web Animations API returns a new AnimationPlaybackEvent object instance. | 84 | 84 | 63 | 13.1 | 84 | 13.4 |
| The currentTime read-only property of the AnimationPlaybackEvent interface represents the current time of the animation that generated the event at the moment the event is queued. This will be unresolved if the animation was idle at the time the event was generated. | 84 | 84 | 63 | 13.1 | 84 | 13.4 |
| The timelineTime read-only property of the AnimationPlaybackEvent interface represents the time value of the animation's AnimationTimeline at the moment the event is queued. This will be unresolved if the animation was not associated with a timeline at the time the event was generated or if the associated timeline was inactive. | 84 | 84 | 63 | 13.1 | 84 | 13.4 |
| The AnimationTimeline interface of the Web Animations API represents the timeline of an animation. This interface exists to define timeline features, inherited by other timeline types: | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
| The currentTime read-only property of the Web Animations API's AnimationTimeline interface returns the timeline's current time in milliseconds, or null if the timeline is inactive. | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
| The duration read-only property of the Web Animations API's AnimationTimeline interface returns the maximum value for this timeline or null. | 115 | 115 | | 26 | 115 | 26 |
| The getAnimations() method of the Document interface returns an array of all Animation objects currently in effect whose target elements are descendants of the document. This array includes CSS Animations, CSS Transitions, and Web Animations. | 84 | 84 | 75 | 14 | 84 | 14 |
| The timeline readonly property of the Document interface represents the default timeline of the current document. This timeline is a special instance of DocumentTimeline. | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
| The DocumentTimeline interface of the Web Animations API represents animation timelines, including the default document timeline (accessed via Document.timeline). | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
| The DocumentTimeline() constructor of the Web Animations API creates a new instance of the DocumentTimeline object associated with the active document of the current browsing context. | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
| The Element interface's animate() method is a shortcut method which creates a new Animation, applies it to the element, then plays the animation. It returns the created Animation object instance. | 36 | 79 | 48 | 13.1 | 36 | 13.4 |
| Implicit to/from keyframes are supported | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
animate (options composite parameter) `options.composite` parameter | 84 | 84 | 80 | 16 | 84 | 16 |
animate (options id parameter) `options.id` parameter | 50 | 79 | 48 | 13.1 | 50 | 13.4 |
animate (options iterationComposite parameter) `options.iterationComposite` parameter | | | 80 | 16.4 | | 16.4 |
animate (options pseudoElement parameter) `options.pseudoElement` parameter | 84 | 84 | 75 | 14 | 84 | 14 |
animate (options rangeEnd parameter) `options.rangeEnd` parameter | 115 | 115 | | 26 | 115 | 26 |
animate (options rangeStart parameter) `options.rangeStart` parameter | 115 | 115 | | 26 | 115 | 26 |
animate (options timeline parameter) `options.timeline` parameter | 85 | 85 | | 16 | 85 | 16 |
| The animationcancel event is fired when a CSS Animation unexpectedly aborts. In other words, any time it stops running without sending an Element/animationend_event event. This might happen when the animation-name is changed such that the animation is removed, or when the animating node is hidden using CSS. Therefore, either directly or because any of its… | 83 | 83 | 54 | 13.1 | 83 | 13.4 |
| The animationend event is fired when a CSS Animation has completed. If the animation aborts before reaching completion, such as if the element is removed from the DOM or the animation is removed from the element, the animationend event is not fired. | 79 | 18 | 51 | 9 | 79 | 9 |
| The animationiteration event is fired when an iteration of a CSS Animation ends, and another one begins. This event does not occur at the same time as the Element/animationend_event event, and therefore does not occur for animations with an animation-iteration-count of one. | 79 | 18 | 51 | 9 | 79 | 9 |
| The animationstart event is fired when a CSS Animation has started. If there is an animation-delay, this event will fire once the delay period has expired. A negative delay will cause the event to fire with an AnimationEvent/elapsedTime equal to the absolute value of the delay (and, correspondingly, the animation will begin playing at that time index into… | 79 | 18 | 51 | 9 | 79 | 9 |
| The getAnimations() method of the Element interface returns an array of all Animation objects affecting this element, or that are scheduled to do so in the future. It can optionally return Animation objects either for descendant elements and their pseudo-elements or just for the specified pseudo-element. | 84 | 84 | 75 | 13.1 | 84 | 13.4 |
| The KeyframeEffect interface of the Web Animations API lets us create sets of animatable properties and values, called keyframes. These can then be played using the Animation.Animation constructor. | 75 | 79 | 63 | 13.1 | 75 | 13.4 |
| The composite property of a KeyframeEffect resolves how an element's animation impacts its underlying property values. | 84 | 84 | 80 | 16 | 84 | 16 |
| The getKeyframes() method of a KeyframeEffect returns an Array of the computed keyframes that make up this animation along with their computed offsets. | 84 | 84 | 63 | 13.1 | 84 | 13.4 |
| The iterationComposite property of a KeyframeEffect resolves how the animation's property value changes accumulate or override each other upon each of the animation's iterations. | | | 80 | 16.4 | | 16.4 |
| The KeyframeEffect() constructor of the Web Animations API returns a new KeyframeEffect object instance, and also allows you to clone an existing keyframe effect object instance. | 75 | 79 | 63 | 13.1 | 75 | 13.4 |
| The pseudoElement property of a KeyframeEffect interface is a string representing the pseudo-element being animated. It may be null for animations that do not target a pseudo-element. It performs as both a getter and a setter, except with animations and transitions generated by CSS. | 84 | 84 | 75 | 14 | 84 | 14 |
| The setKeyframes() method of the KeyframeEffect interface replaces the keyframes that make up the affected KeyframeEffect with a new set of keyframes. | 84 | 84 | 63 | 13.1 | 84 | 13.4 |
| The target property of a KeyframeEffect interface represents the element or pseudo-element being animated. It may be null for animations that do not target a specific element. It performs as both a getter and a setter, except with animations and transitions generated by CSS. | 75 | 79 | 63 | 13.1 | 75 | 13.4 |
| The getAnimations() method of the ShadowRoot interface returns an array of all Animation objects currently in effect whose target elements are descendants of the shadow tree. This array includes CSS Animations, CSS Transitions, and Web Animations. | 84 | 84 | 75 | 14 | 84 | 14 |
- Before version 59, the pending status was reported by a `"pending"` value returned from `Animation.playState`.
- Before Chrome 50/Opera 37, this property returned `idle` for an animation that had not yet started. Starting with Chrome 50/Opera 37, it shows `paused`.
- Before Firefox 59, this property returned `pending` for Animations with incomplete asynchronous operations but as of Firefox 59 this is indicated by the separate `Animation.pending` property. This reflects recent changes to the specification.
- Before Chrome Android 50/Opera 37, this property returned `idle` for an animation that had not yet started. Starting with Chrome Android 50/Opera 37, it shows `paused`.
- Only the getter is supported
- Only the getter is supported
- Only the getter is supported
- This feature was removed in a later browser version (63)
- Previously available under a different name: AnimationEffectReadOnly (48)
- This browser only partially implements this feature
- This feature was removed in a later browser version (14)
- Implements an older version of the specification, see bug 179536.
- This browser only partially implements this feature
- This feature was removed in a later browser version (14)
- Implements an older version of the specification, see bug 179536.
- This browser only partially implements this feature
- Implementation seems somewhat buggy. More information will follow when available.
- This browser only partially implements this feature
- Implementation seems somewhat buggy. More information will follow when available.
- This browser only partially implements this feature
- The `onanimationcancel` event handler property is not supported. To listen to this event, use `element.addEventListener('animationcancel', function() {});`. See bug 41404325.
- This browser only partially implements this feature
- The `onanimationcancel` event handler property is not supported. To listen to this event, use `element.addEventListener('animationcancel', function() {});`. See bug 41404325.
- This browser only partially implements this feature
- This feature was removed in a later browser version (13.1)
- Although the `onanimationcancel` event handler property is supported, the `animationcancel` event is never fired.
- This browser only partially implements this feature
- The `onanimationcancel` event handler property is not supported. To listen to this event, use `element.addEventListener('animationcancel', function() {});`. See bug 41404325.
- This browser only partially implements this feature
- This feature was removed in a later browser version (13.4)
- Although the `onanimationcancel` event handler property is supported, the `animationcancel` event is never fired.
- This browser only partially implements this feature
- This feature was removed in a later browser version (79)
- The `onanimationend` event handler property is not supported. To listen to this event, use `document.addEventListener('animationend', function() {});`.
- Available with a vendor prefix: webkit (81)
- This browser only partially implements this feature
- This feature was removed in a later browser version (18)
- The `onanimationend` event handler property is not supported. To listen to this event, use `document.addEventListener('animationend', function() {});`.
- Available with a vendor prefix: webkit (81)
- This browser only partially implements this feature
- This feature was removed in a later browser version (51)
- The `onanimationend` event handler property is not supported. To listen to this event, use `document.addEventListener('animationend', function() {});`.
- This browser only partially implements this feature
- This feature was removed in a later browser version (79)
- The `onanimationend` event handler property is not supported. To listen to this event, use `document.addEventListener('animationend', function() {});`.
- Available with a vendor prefix: webkit (81)
- This browser only partially implements this feature
- This feature was removed in a later browser version (79)
- The `onanimationiteration` event handler property is not supported. To listen to this event, use `document.addEventListener('animationiteration', function() {});`.
- Available with a vendor prefix: webkit (81)
- This browser only partially implements this feature
- This feature was removed in a later browser version (18)
- The `onanimationiteration` event handler property is not supported. To listen to this event, use `document.addEventListener('animationiteration', function() {});`.
- Available with a vendor prefix: webkit (81)
- This browser only partially implements this feature
- This feature was removed in a later browser version (51)
- The `onanimationiteration` event handler property is not supported. To listen to this event, use `document.addEventListener('animationiteration', function() {});`.
- This browser only partially implements this feature
- This feature was removed in a later browser version (79)
- The `onanimationiteration` event handler property is not supported. To listen to this event, use `document.addEventListener('animationiteration', function() {});`.
- Available with a vendor prefix: webkit (81)
- This browser only partially implements this feature
- This feature was removed in a later browser version (79)
- The `onanimationstart` event handler property is not supported. To listen to this event, use `document.addEventListener('animationstart', function() {});`.
- Available with a vendor prefix: webkit (81)
- This browser only partially implements this feature
- This feature was removed in a later browser version (18)
- The `onanimationstart` event handler property is not supported. To listen to this event, use `document.addEventListener('animationstart', function() {});`.
- Available with a vendor prefix: webkit (81)
- This browser only partially implements this feature
- This feature was removed in a later browser version (51)
- The `onanimationstart` event handler property is not supported. To listen to this event, use `document.addEventListener('animationstart', function() {});`.
- This browser only partially implements this feature
- This feature was removed in a later browser version (79)
- The `onanimationstart` event handler property is not supported. To listen to this event, use `document.addEventListener('animationstart', function() {});`.
- Available with a vendor prefix: webkit (81)
Use cases
-
Using Web animations
The Animation interface of the Web Animations API represents a single animation player and provides playback controls and a timeline for an animation node or source.
Cautions
- May not be supported in older browsers.
Implementation notes
- Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.