JavaScript Element transitioncancel Event

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
DOM event
Instance event

What You’ll Learn

The transitioncancel event fires when a CSS transition is canceled instead of finishing with transitionend. Learn addEventListener vs ontransitioncancel, TransitionEvent properties, how it fits with transitionrun / transitionstart / transitionend, and five try-it labs.

01

Kind

Instance event

02

Type

TransitionEvent

03

When

Transition canceled

04

Handler

ontransitioncancel

05

Pair with

transitionend

06

Status

Baseline Widely

Introduction

CSS transitions usually end with transitionend. Sometimes they stop early—for example you leave a :hover state before the transition finishes, or you remove the class that was driving the property change. In those cases the browser fires transitioncancel instead of transitionend.

That makes transitioncancel useful for cleanup: reset UI labels, cancel follow-up work you only wanted after a completed transition, or log that the motion did not finish normally.

💡
Beginner tip

If transitioncancel fires for a transition, transitionend will not fire for that same transition. Handle both events when you need reliable cleanup either way.

Understanding transitioncancel

An instance event on elements that participate in CSS Transitions. MDN: it fires when a CSS transition is canceled—after transitionrun and before a normal transitionend.

  • Cancels when the transition is interrupted in either direction mid-flight.
  • TransitionEvent — includes propertyName, elapsedTime, pseudoElement.
  • Not the normal “transition finished” signal—that is transitionend.
  • Baseline Widely available — solid modern browser support (since Nov 2020).

📝 Syntax

Use the event name with addEventListener, or set the handler property:

JavaScript
addEventListener("transitioncancel", (event) => { });

ontransitioncancel = (event) => { };

Event type

A TransitionEvent (inherits from Event).

Event properties

PropertyMeaning
propertyNameThe CSS property name associated with the transition
elapsedTimeSeconds the transition had been running when the event fired (not affected by transition-delay)
pseudoElement:: name if the transition runs on a pseudo-element; otherwise ""

⚖️ Transition lifecycle events

EventWhen it firesTypical use
transitionrunTransition is created (may still be in delay)Know a transition was scheduled
transitionstartTransition actually starts animating (after delay)Mark UI as “in motion”
transitionendTransition finishes normallyCleanup after success
transitioncancelTransition is aborted earlyCleanup after interrupt

MDN notes: if there is no delay or duration (both 0s or undeclared), there is no transition—and none of these events fire.

⚡ Quick Reference

GoalCode
Listenel.addEventListener("transitioncancel", fn)
Handler propertyel.ontransitioncancel = fn
Trigger (hover)Leave :hover before the transition ends
Trigger (class)Remove the class that drives the target styles mid-flight
Read propertyevent.propertyName
Read timeevent.elapsedTime
MDN statusBaseline Widely available

🔍 At a Glance

Four facts to remember about transitioncancel.

Event type
TransitionEvent

Property + time

Means
canceled

Not transitionend

Common trigger
leave early

Hover / class off

Baseline
yes

Widely available

Examples Gallery

Examples follow MDN Element: transitioncancel event. Try It Yourself labs start a CSS transition, then cancel it so you can see the event fire.

📚 Getting Started

Register handlers the MDN ways, then cancel mid-transition.

Example 1 — addEventListener("transitioncancel")

MDN: listen on a transitioning element, then interrupt before it finishes.

JavaScript
const box = document.querySelector(".transition");

box.addEventListener("transitioncancel", () => {
  console.log("Transition canceled");
});

// Start then interrupt before the 2s transition ends:
box.classList.add("grown");
setTimeout(() => {
  box.classList.remove("grown");
}, 400);
Try It Yourself

How It Works

Removing the driving class reverses or aborts the in-flight transition, so the browser fires transitioncancel instead of waiting for a normal transitionend.

Example 2 — ontransitioncancel Property

MDN’s alternate style using the event handler property.

JavaScript
const box = document.querySelector(".transition");

box.ontransitioncancel = () => {
  console.log("Transition canceled");
};

box.classList.add("grown");
setTimeout(() => {
  box.classList.remove("grown");
}, 400);
Try It Yourself

How It Works

Same event, different registration API. Prefer addEventListener when you need multiple listeners or easy removal.

📈 Details, Remove & Lifecycle

Read TransitionEvent fields, cancel by toggling styles, watch the full set.

Example 3 — Read propertyName and elapsedTime

Use TransitionEvent properties for logging or debugging.

JavaScript
const box = document.getElementById("box");

box.addEventListener("transitioncancel", (event) => {
  console.log("canceled:", event.propertyName);
  console.log("elapsedTime:", event.elapsedTime);
  console.log("pseudoElement:", JSON.stringify(event.pseudoElement));
});

box.classList.add("grown");
setTimeout(() => {
  box.classList.remove("grown");
}, 300);
Try It Yourself

How It Works

elapsedTime is how long the transition had been running (in seconds) when cancel fired. MDN notes it is not affected by transition-delay. Multiple properties may each produce their own cancel event.

Example 4 — Cancel by Removing the Driving Class

Start a long transition with a class, then remove that class mid-flight.

JavaScript
const box = document.getElementById("box");
const out = document.getElementById("out");

box.addEventListener("transitioncancel", () => {
  out.textContent = "Transition canceled (class removed)";
});

box.classList.add("grown");
setTimeout(() => {
  box.classList.remove("grown");
}, 250);
Try It Yourself

How It Works

Class toggles are a reliable lab-friendly cancel path. On real pages, leaving :hover early is the classic MDN demo of the same idea.

Example 5 — Full Lifecycle Log

Inspired by MDN’s live example: log run, start, cancel, and end together.

JavaScript
const el = document.querySelector(".transition");
const message = document.querySelector(".message");
const btn = document.getElementById("toggle");

el.addEventListener("transitionrun", () => {
  message.textContent = "transitionrun fired";
});
el.addEventListener("transitionstart", () => {
  message.textContent = "transitionstart fired";
});
el.addEventListener("transitioncancel", () => {
  message.textContent = "transitioncancel fired";
});
el.addEventListener("transitionend", () => {
  message.textContent = "transitionend fired";
});

btn.addEventListener("click", () => {
  el.classList.toggle("grown");
});
Try It Yourself

How It Works

Toggle the class on to start the transition; toggle it off before it finishes to see transitioncancel. Leave it on until the end to see transitionend instead. MDN’s hover demo works the same way—stop hovering early to cancel.

🚀 Common Use Cases

  • Cleaning up UI state when a panel closes mid-transition.
  • Distinguishing “finished” vs “interrupted” transition analytics.
  • Skipping follow-up logic that should only run after a completed motion.
  • Teaching the full CSS transition event set alongside transitionend.
  • Coordinating class toggles that both start and reverse property changes.

🔧 How It Works

1

Transition is created

transitionrun fires; transitionstart follows after any delay.

Schedule
2

Something cancels it

Leave hover early, remove the driving class, or reverse the change mid-flight.

Interrupt
3

Browser fires transitioncancel

A TransitionEvent is dispatched (no matching transitionend).

Event
4

Your handler cleans up

Log, reset classes, or update UI for an interrupted transition.

📝 Notes

  • MDN: Baseline Widely available (since November 2020).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • If transitioncancel fires, transitionend will not fire for that transition.
  • Zero delay and duration means no transition events at all.
  • Related learning: animationcancel, touchstart, addEventListener(), JavaScript hub.

Browser Support

transitioncancel is marked Baseline Widely available on MDN (across browsers since November 2020). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline · Widely available

Element transitioncancel

Fires when a CSS transition is canceled; TransitionEvent exposes propertyName, elapsedTime, and pseudoElement.

Full Widely available
Google Chrome 87+ (full) · earlier partial
Yes
Mozilla Firefox 53+
Yes
Apple Safari 13.1+
Yes
Microsoft Edge 87+ Chromium
Yes
Opera 73+
Yes
Internet Explorer No transitioncancel support
Unavailable
transitioncancel Baseline

Bottom line: Listen with addEventListener("transitioncancel", …), pair it with transitionend for cleanup, and remember cancel replaces end for that transition.

Conclusion

transitioncancel tells you a CSS transition was interrupted instead of finishing with transitionend. Listen with addEventListener, read TransitionEvent details when you need them, and handle both end and cancel for reliable cleanup.

Continue with transitionend, animationcancel, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use addEventListener("transitioncancel", ...)
  • Handle both transitionend and transitioncancel for cleanup
  • Give transitions a real duration/delay when you expect events
  • Log propertyName when several properties transition
  • Keep cancel handlers light and idempotent

❌ Don’t

  • Assume every transition stop fires transitionend
  • Expect events when duration and delay are both 0s
  • Forget that cancel replaces end for that transition
  • Confuse CSS Transitions with CSS Animations / Web Animations
  • Ignore multi-property cancel events (one per property)

Key Takeaways

Knowledge Unlocked

Five things to remember about transitioncancel

CSS transition aborted—cleanup without waiting for transitionend.

5
Core concepts
🎨 02

TransitionEvent

property + time

API
👁️ 03

Leave early

hover / class

Trigger
🔔 04

addEventListener

preferred

Listen
🎯 05

Baseline

widely available

Compat

❓ Frequently Asked Questions

It fires when a CSS transition is canceled — after transitionrun has occurred and before a normal transitionend. Common causes include reversing or removing the transition mid-flight (for example leaving a :hover state early, or removing the class that drove the change).
No. MDN does not mark Element transitioncancel as Deprecated, Experimental, or Non-standard. It is Baseline Widely available (across browsers since November 2020).
A TransitionEvent. Useful read-only properties include propertyName, elapsedTime, and pseudoElement.
Prefer element.addEventListener("transitioncancel", handler). You can also set ontransitioncancel where supported.
transitionend fires when a transition finishes its intended run. transitioncancel fires when the transition is aborted early. If transitioncancel fires, transitionend will not fire for that transition.
If there is no transition delay or duration — both are 0s or neither is declared — there is no transition, and none of the transition events fire.
Did you know?

MDN’s classic demo uses a long transition-delay plus hover: leave the box before the motion finishes and you get transitioncancel; stay until the end and you get transitionend. Same idea works with class toggles in try-it labs.

Next: transitionend

Learn when a CSS transition finishes normally.

transitionend →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful