The animationcancel event fires when a CSS Animation aborts instead of finishing with animationend. Learn addEventListener vs onanimationcancel, AnimationEvent properties, common cancel triggers (hide element, change animation-name), and why MDN marks this event Limited availability.
01
Kind
Instance event
02
Type
AnimationEvent
03
When
Animation aborted
04
Handler
onanimationcancel
05
Pair with
animationend
06
Status
Limited availability
Fundamentals
Introduction
CSS animations usually end with animationend. Sometimes they stop unexpectedly—for example you hide the element with display: none, or you change animation-name so the running animation is removed. In those cases the browser should fire animationcancel instead of animationend.
That makes animationcancel useful for cleanup: release state, reset UI labels, or log that the animation did not finish normally.
💡
Beginner tip
Prefer addEventListener("animationcancel", ...). Some Chromium builds historically supported the event via addEventListener but not the onanimationcancel property.
Concept
Understanding animationcancel
An instance event on elements that participate in CSS Animations. MDN: it fires when a CSS Animation unexpectedly aborts—any time it stops without sending animationend.
Aborts when the animation is removed or the node is hidden (directly or via an ancestor).
AnimationEvent — includes animationName, elapsedTime, pseudoElement.
Not the normal “animation finished” signal—that is animationend.
Limited availability — not Baseline; verify on your target browsers.
Foundation
📝 Syntax
Use the event name with addEventListener, or set the handler property:
Seconds the animation had been running (paused time excluded)
pseudoElement
:: name if animated on a pseudo-element; otherwise ""
Compare
⚖️ Animation lifecycle events
Event
When it fires
Typical use
animationstart
Animation begins
Mark UI as “playing”
animationiteration
Each iteration ends (except the last)
Count loops
animationend
Animation finishes normally
Cleanup after success
animationcancel
Animation aborts early
Cleanup after interrupt
Caveat
⚠️ Limited Availability (Not Baseline)
MDN labels animationcancel as Limited availability: it is not Baseline because support is incomplete in some widely used browsers. Prefer addEventListener over onanimationcancel for broader coverage.
It is still a standard CSS Animations event—not Deprecated, Experimental, or Non-standard. Always test cancel paths (hide, remove class, change animation-name) on your supported browsers.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Listen
el.addEventListener("animationcancel", fn)
Handler property
el.onanimationcancel = fn
Trigger (hide)
el.style.display = "none"
Trigger (remove)
Clear/change animation-name or remove animating class
Read name
event.animationName
Read time
event.elapsedTime
MDN status
Limited availability (not Baseline)
Snapshot
🔍 At a Glance
Four facts to remember about animationcancel.
Event type
AnimationEvent
Name + time
Means
aborted
Not animationend
Common trigger
display:none
Or remove name
Baseline
no
Limited availability
Hands-On
Examples Gallery
Examples follow MDN Element: animationcancel event. Try It Yourself labs start a short CSS animation, then cancel it so you can see the event fire.
📚 Getting Started
Register handlers the MDN ways, then cancel by hiding.
Example 1 — addEventListener("animationcancel")
MDN: listen on an animating element, then set display: none to abort.
animationcancel is a standard CSS Animations event, but MDN marks it Limited availability (not Baseline). Logos use the shared browser-image-sprite.png sprite from this project. Prefer addEventListener; some Chromium versions historically lacked onanimationcancel.
✓ Limited availability · Not Baseline
Element animationcancel
Supported in modern Firefox, Safari (13.1+), and Chromium engines for the event itself—always verify cancel paths and handler-property support.
LimitedNot Baseline
Google Chrome83+ event · prefer addEventListener
Supported
Mozilla FirefoxSupported since Firefox 54+
Full support
Apple Safari13.1+ (earlier builds incomplete)
Supported
Microsoft Edge83+ Chromium · prefer addEventListener
Supported
Opera69+ · Chromium-based
Supported
Internet ExplorerNo animationcancel support
Unavailable
animationcancelLimited
Bottom line: Use addEventListener("animationcancel", …) and test hide / remove-animation cases on your supported browsers.
Wrap Up
Conclusion
animationcancel tells you a CSS animation was interrupted instead of finishing with animationend. Listen with addEventListener, read AnimationEvent details when you need them, and remember support is not Baseline everywhere.
Handle both animationend and animationcancel for cleanup
Test hide / class-remove cancel paths on real browsers
Log animationName when debugging multiple animations
Keep cancel handlers light and idempotent
❌ Don’t
Assume every animation stop fires animationend
Rely only on onanimationcancel in Chromium
Assume Baseline support without checking MDN
Confuse Web Animations API cancel with this CSS event
Forget ancestor display: none can cancel child animations
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about animationcancel
CSS animation aborted—cleanup without waiting for animationend.
5
Core concepts
🚫01
Means aborted
not finished
Event
🎬02
AnimationEvent
name + time
API
👁️03
Hide cancels
display:none
Trigger
🔔04
addEventListener
preferred
Listen
⚠️05
Not Baseline
limited
Compat
❓ Frequently Asked Questions
It fires when a CSS Animation stops unexpectedly — that is, it stops running without sending an animationend event. Common causes include changing animation-name so the animation is removed, or hiding the element (or an ancestor) with CSS such as display: none.
No. MDN does not mark Element animationcancel as Deprecated, Experimental, or Non-standard. It is a standard CSS Animations event, but MDN labels it Limited availability (not Baseline) because support is missing or incomplete in some browsers.
An AnimationEvent. Useful read-only properties include animationName, elapsedTime, and pseudoElement.
Prefer element.addEventListener("animationcancel", handler). You can also set onanimationcancel where supported. In some Chromium versions the handler property was missing even though addEventListener worked — so addEventListener is the safer choice.
animationend fires when an animation finishes its intended run (including after the last iteration). animationcancel fires when the animation is aborted early and never reaches a normal end.
Yes in supporting browsers: setting display: none on the animating element (or a containing node that hides it) can abort the animation and fire animationcancel instead of animationend.
Did you know?
If an animation runs on a pseudo-element such as ::before, event.pseudoElement starts with :: (for example ::before). For animations on the element itself, it is an empty string.