v145 · Web APIs · CSS Animations
onanimationcancel on GlobalEventHandlers
Chrome 145 exposes onanimationcancel as an event handler property on GlobalEventHandlers (Window, Document, and all Element subclasses). Previously, the animationcancel event could only be listened to via addEventListener — setting element.onanimationcancel = fn was silently ignored. Chrome 145 aligns with the spec and other browsers.
concepts
-
Animationcancel Demo
An element with a running CSS animation. Use the property syntax (
element.onanimationcancel = fn) andaddEventListenerto register handlers, then trigger cancellation and compare which fires. -
Cancel Triggers
Shows all the ways a CSS animation can be cancelled —
display: none, removing from DOM, clearing the animation-name, and settinganimation: none— and howanimationcancelfires for each. -
Cancel-aware Toast
A toast queue that listens for
onanimationcancelso it can log when a toast is interrupted — replaced, yanked withdisplay:none, or removed — for analytics or recovery. -
Loading Spinner
An animated loading spinner with three cancel modes:
display:none,animation:none, and "finish normally". Each mode fires eitheranimationcancel(via the new.onanimationcancelproperty) oranimationend, and the event log shows which — and why.
why it shipped
The animationcancel event was specified in the CSS Animations Level 1 spec alongside animationstart, animationiteration, and animationend. The sibling events have always been available as event handler properties (onanimationstart, onanimationend), but onanimationcancel was missing — a spec oversight that Chrome 145 fixes to achieve consistency and full spec compliance.
the fix
// Before Chrome 145: this was silently ignored
element.onanimationcancel = event => { console.log('cancelled', event.animationName); };
// Before Chrome 145: this worked (but not the property form)
element.addEventListener('animationcancel', event => { /* ... */ });
// Chrome 145+: BOTH now work
element.onanimationcancel = event => { console.log('cancelled', event.animationName); };
element.addEventListener('animationcancel', event => { /* ... */ });
// Also works on window
window.onanimationcancel = event => { console.log('global cancel:', event.animationName); };
// animationcancel fires when:
// - element gets display: none
// - element is removed from DOM
// - animation-name is changed/removed
// - animation: none is set
// - element gets visibility: hidden (in some cases)