Animation: cancel() method

Baseline 2022

Newly available

Since September 2022, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

The Web Animations API's cancel() method of the Animation interface clears all KeyframeEffects caused by this animation and aborts its playback.

Note: When an animation is cancelled, its startTime and currentTime are set to null.

Syntax

js
cancel()

Parameters

None.

Return value

None (undefined).

Exceptions

This method doesn't directly throw exceptions; however, if the animation's playState is anything but "idle" when cancelled, the current finished promise is rejected with a DOMException named AbortError.

Specifications

Specification
Web Animations
# dom-animation-cancel

Browser compatibility

BCD tables only load in the browser

See also