JavaScript Element touchcancel Event

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

What You’ll Learn

The touchcancel event fires when one or more touch points are disrupted. Learn TouchEvent, changedTouches, how it differs from touchend, cleanup patterns, Pointer Events alternatives, and five try-it labs.

01

Kind

Instance event

02

Type

TouchEvent

03

When

Touch disrupted

04

Handler

ontouchcancel

05

Bubbles?

Yes

06

Status

Limited availability

Introduction

Touch gestures do not always end with a clean finger lift. touchcancel means the browser or device aborted the touch—so your drag, press, or multi-touch state should reset.

MDN lists common causes: switching apps / Home button, orientation change, palm rejection, touch-action stopping the input, or too many simultaneous fingers. Treat cancel like an emergency stop, not a successful tap.

💡
Beginner tip

For new cross-device UIs, prefer Pointer Events (pointercancel. Keep touchcancel when you maintain Touch Events code or need touch-only behavior.

Understanding touchcancel

An instance event that answers: “Was this touch aborted before a normal lift?”

  • Trigger — touch points disrupted (system / UA / CSS / hardware).
  • Event typeTouchEvent; use changedTouches.
  • Bubbles — yes; typically not cancelable (no default action).
  • Job — clean up press/drag state; do not treat as a click.
  • Limited availability on MDN (not Baseline)—desktop Safari often lacks Touch Events.

⚡ When touchcancel Fires

  • Hardware / OS interrupts (Home, app switcher).
  • Screen orientation changes mid-touch.
  • Palm rejection or accidental-touch heuristics.
  • touch-action CSS prevents the gesture from continuing.
  • Too many simultaneous contact points for the implementation.

📝 Syntax

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

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

ontouchcancel = (event) => { };

Event type

A TouchEvent (inherits from UIEvent / Event).

Handy TouchEvent properties

PropertyMeaning
changedTouchesTouch points whose state changed (the canceled ones)
touchesAll current contact points on the surface
targetTouchesContacts that started on this event target and are still down
altKey / ctrlKey / metaKey / shiftKeyModifier keys at event time

⚡ Quick Reference

GoalCode / note
Listenel.addEventListener("touchcancel", fn)
Handler propertyel.ontouchcancel = fn
Canceled pointsevent.changedTouches
CleanupReset drag / press UI; do not fire click logic
Cross-devicePrefer Pointer Events + pointercancel
MDN statusLimited availability (not Baseline)

🔍 At a Glance

Four facts to remember about touchcancel.

Event type
TouchEvent

changedTouches

Means
aborted

Not a lift

Bubbles
true

Listen on el

Baseline
no

Limited availability

Examples Gallery

Patterns follow MDN Element: touchcancel event and the Touch events guide. Use a touch device or DevTools touch simulation; some labs include a button that runs the same cleanup handler for desktop practice.

📚 Getting Started

Listen for cancel and read the TouchEvent.

Example 1 — Log touchcancel

Print a message whenever an active touch is aborted.

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

pad.addEventListener("touchcancel", (event) => {
  out.textContent =
    "touchcancel · changed=" + event.changedTouches.length;
});
Try It Yourself

How It Works

On a phone, start a touch on the pad then press Home or rotate the device to trigger cancel.

Example 2 — ontouchcancel Property

Same idea using the handler property form.

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

pad.ontouchcancel = (event) => {
  out.textContent = "ontouchcancel fired";
};
Try It Yourself

How It Works

Prefer addEventListener when you need multiple listeners or easy removal.

📈 Touches, Cleanup & Detect

Inspect canceled points, reset UI, and feature-detect Touch Events.

Example 3 — Read changedTouches

Log identifiers for each canceled contact point.

JavaScript
pad.addEventListener("touchcancel", (event) => {
  const ids = [];
  for (let i = 0; i < event.changedTouches.length; i++) {
    ids.push(event.changedTouches[i].identifier);
  }
  out.textContent = "canceled ids: " + ids.join(", ");
});
Try It Yourself

How It Works

changedTouches lists the points that just changed—here, the ones that were canceled.

Example 4 — Drag Cleanup on Cancel

Start a drag on touchstart; reset styles on touchcancel (and touchend).

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

function endDrag(reason) {
  pad.classList.remove("dragging");
  out.textContent = reason;
}

pad.addEventListener("touchstart", () => {
  pad.classList.add("dragging");
  out.textContent = "dragging…";
}, { passive: true });

pad.addEventListener("touchend", () => endDrag("touchend · released"));
pad.addEventListener("touchcancel", () => endDrag("touchcancel · aborted"));
Try It Yourself

How It Works

Always pair press/drag start with both normal end and cancel so UI never sticks in a pressed state.

Example 5 — Feature Detect + Pointer Fallback Note

Check Touch Events support; prefer Pointer Events when building new UIs.

JavaScript
const out = document.getElementById("out");
const hasTouch = "ontouchcancel" in window;

out.textContent = hasTouch
  ? "Touch Events available — listen for touchcancel"
  : "No Touch Events — use Pointer Events (pointercancel)";

if (hasTouch) {
  document.getElementById("pad").addEventListener("touchcancel", () => {
    out.textContent = "touchcancel received";
  });
}
Try It Yourself

How It Works

Many desktop browsers hide Touch Events even with a touchscreen—feature-detect and plan a Pointer Events path.

🚀 Common Use Cases

  • Reset drag-and-drop or slider state when the OS interrupts a touch.
  • Cancel long-press menus if the finger is aborted mid-hold.
  • Clear multi-touch drawing / pinch state on interruption.
  • Avoid firing “tap completed” logic when the gesture was canceled.
  • Migrate touch-only apps toward pointercancel for mouse + pen + touch.

🔧 How It Works

1

Touch starts

touchstart (and maybe touchmove) while the finger is down.

Active
2

Disruption

Home, rotation, palm rejection, touch-action, or too many fingers.

Interrupt
3

touchcancel fires

TouchEvent with changedTouches for aborted points.

Event
4

Clean up

Reset UI; do not treat the gesture as a successful click.

📝 Notes

  • MDN: Limited availability (not Baseline)—no Deprecated / Experimental / Non-standard banner.
  • Desktop Safari often lacks Touch Events; test on iOS Safari / Android browsers.
  • Prefer Pointer Events for new cross-device interaction code.
  • Always clean up on both touchend and touchcancel.
  • Related learning: securitypolicyviolation, pointerup, addEventListener(), JavaScript hub.

Limited Browser Availability

touchcancel is marked Limited availability on MDN (not Baseline). Logos use the shared browser-image-sprite.png sprite from this project. Touch Events are strong on mobile; many desktop browsers omit them—prefer Pointer Events for cross-device UIs.

Limited availability

Element touchcancel

Fires when touch points are disrupted. Chrome 22+, Firefox 52+, Edge 12+, Safari iOS yes; desktop Safari often no.

Partial Not Baseline
Google Chrome 22+ (touch-capable / mobile)
Supported
Mozilla Firefox 52+ (desktop re-enabled)
Supported
Apple Safari iOS yes · desktop often no
Partial
Microsoft Edge 12+
Supported
Opera Mobile / Chromium touch paths
Partial
Internet Explorer Not supported (use Pointer Events)
Unavailable
touchcancel Limited

Bottom line: Use touchcancel for Touch Events cleanup on mobile. For mouse + pen + touch together, ship pointercancel with Pointer Events.

Conclusion

touchcancel is the “touch aborted” signal in the Touch Events API. Listen for it whenever you track press or drag state, reset UI on cancel, and consider Pointer Events when you need the same idea across mouse, pen, and touch.

Continue with touchend, pointerup, addEventListener(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Clean up on both touchend and touchcancel
  • Read changedTouches for canceled contact points
  • Test with DevTools touch simulation or a real phone
  • Prefer Pointer Events for new multi-input UIs
  • Use passive listeners for touchstart/touchmove when you do not call preventDefault

❌ Don’t

  • Treat touchcancel as a successful tap or click
  • Leave drag/press styles stuck when a touch is aborted
  • Assume desktop Safari exposes Touch Events
  • Detect “mobile” only by checking for ontouchstart
  • Overwrite ontouchcancel if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about touchcancel

Touch aborted—clean up state, do not count it as a successful lift.

5
Core concepts
📄02

TouchEvent

changedTouches

API
03

vs end

abort ≠ lift

Compare
🧹04

Cleanup

reset drag UI

Pattern
🎯05

Limited

prefer pointers

Status

❓ Frequently Asked Questions

It fires when one or more touch points are disrupted in an implementation-specific way—for example the user presses Home, switches apps, the screen rotates, palm rejection cancels input, or touch-action stops the gesture.
No. MDN does not mark Element touchcancel as Deprecated, Experimental, or Non-standard. It has Limited availability (not Baseline), mainly because desktop Safari and some desktop browsers omit or limit Touch Events.
A TouchEvent. Use changedTouches for the touch points that were canceled; also inspect touches and targetTouches as needed.
touchend means the user lifted a finger normally. touchcancel means the system or browser aborted the touch—treat it as cleanup, not a successful tap.
For cross-device UIs (mouse, pen, and touch), MDN recommends Pointer Events. pointercancel is the close cousin of touchcancel for aborted pointers.
Use Chrome Device mode or Firefox Responsive Design Mode with touch simulation. On a phone, press Home or rotate the device while touching the page.
Did you know?

Some desktop browsers hide Touch Events on purpose so sites do not assume “has ontouchstart = mobile phone.” That is a big reason MDN marks Touch Events as Limited availability—not because phones lack touchcancel.

Next: touchend

Handle the normal finger-up signal in Touch Events.

touchend →

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