JavaScript Element pointercancel Event

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

What You’ll Learn

The pointercancel event fires when the browser cancels an active pointer. Learn addEventListener vs onpointercancel, common cancel causes, the follow-up pointerout / pointerleave sequence, gesture cleanup, and five try-it labs.

01

Kind

Instance event

02

Type

PointerEvent

03

When

Pointer cancelled

04

Handler

onpointercancel

05

Follow-up

pointerout · pointerleave

06

Status

Baseline widely available

Introduction

Not every pointer session ends with a clean pointerup. The OS or browser may steal the gesture—home button, app switcher, orientation change, palm rejection, viewport pan/zoom, or touch-action scrolling.

pointercancel is the signal: “This pointer will not continue.” Abort drag/draw state immediately so your UI does not stay stuck in a pressed or dragging mode.

💡
Beginner tip

After pointercancel, MDN notes the browser also fires pointerout then pointerleave. Treat cancel as the end of the active pointer, then expect those leave events.

Understanding pointercancel

An instance event that answers: “Did the browser cancel this pointer?”

  • Fires when more pointer events are unlikely, or the pointer starts panning/zooming/scrolling the viewport after pointerdown.
  • PointerEventpointerId, pointerType, isPrimary, and more.
  • Handleronpointercancel or addEventListener("pointercancel", ...).
  • Follow-uppointerout then pointerleave.
  • Baseline Widely available on MDN (since July 2020).

📝 Syntax

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

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

onpointercancel = (event) => { };

Event type

A PointerEvent (inherits from MouseEvent and Event).

Handy properties

PropertyMeaning
pointerIdUnique id for this pointer stream
pointerTypeDevice kind: mouse, pen, touch, etc.
isPrimaryWhether this is the primary pointer of that type
pressure / width / heightContact geometry and pressure when available

⚡ When pointercancel Fires

MDN lists common situations that can trigger it:

  • Hardware / OS interrupts (app switcher, mobile Home button).
  • Screen orientation changes while the pointer is active.
  • Accidental input detection (for example palm rejection with a stylus).
  • touch-action CSS preventing the input from continuing (browser takes over for pan/zoom).
  • Too many simultaneous pointers—the browser may cancel existing ones.

⚡ Quick Reference

GoalCode / note
Listenel.addEventListener("pointercancel", fn)
Handler propertyel.onpointercancel = fn
Identify pointerevent.pointerId, event.pointerType
Clean up dragClear classes / flags on cancel and pointerup
After cancelExpect pointerout then pointerleave
MDN statusBaseline Widely available (Jul 2020)

🔍 At a Glance

Four facts to remember about pointercancel.

Event type
PointerEvent

MouseEvent + more

Means
aborted

Not a normal up

Then
out → leave

MDN sequence

Baseline
yes

Since Jul 2020

Examples Gallery

Examples follow MDN Element: pointercancel event. On desktop, cancel is harder to trigger than pointerup—labs also show how to wire cleanup so you are ready when it does fire (touch devices / pan gestures).

📚 Getting Started

MDN listener patterns and the handler property.

Example 1 — Log pointercancel (MDN)

Listen for the cancel signal on a surface.

JavaScript
const para = document.querySelector("p");
const out = document.getElementById("out");

para.addEventListener("pointercancel", (event) => {
  out.textContent =
    "Pointer event cancelled (id=" + event.pointerId + ")";
});
Try It Yourself

How It Works

On many desktop mice you may only see pointerup. Cancel is more common with touch, stylus, and browser-taken gestures.

Example 2 — onpointercancel Property (MDN)

Same idea using the handler property form.

JavaScript
const para = document.querySelector("p");
const out = document.getElementById("out");

para.onpointercancel = (event) => {
  out.textContent = "onpointercancel type=" + event.pointerType;
};
Try It Yourself

How It Works

Prefer addEventListener when you need multiple listeners or easy removal.

📈 Cleanup, Sequence & IDs

Reset drag UI on cancel, observe the leave sequence, and log pointer identity.

Example 3 — Drag Cleanup on Cancel or Up

Start a session on pointerdown; clear it on pointerup or pointercancel.

JavaScript
const handle = document.getElementById("handle");
const out = document.getElementById("out");
let active = false;

function endSession(reason) {
  if (!active) return;
  active = false;
  handle.classList.remove("is-dragging");
  out.textContent = "idle (" + reason + ")";
}

handle.addEventListener("pointerdown", (event) => {
  active = true;
  handle.classList.add("is-dragging");
  handle.setPointerCapture(event.pointerId);
  out.textContent = "dragging…";
});

handle.addEventListener("pointerup", () => endSession("pointerup"));
handle.addEventListener("pointercancel", () => endSession("pointercancel"));
Try It Yourself

How It Works

Listening for both paths keeps the handle from looking “stuck” when the browser cancels the pointer.

Example 4 — Cancel → out → leave

Log the MDN follow-up sequence when cancel fires.

JavaScript
const stage = document.getElementById("stage");
const out = document.getElementById("out");
const log = [];

["pointercancel", "pointerout", "pointerleave"].forEach((type) => {
  stage.addEventListener(type, () => {
    log.push(type);
    out.textContent = log.join(" → ");
  });
});
Try It Yourself

How It Works

Leaving without cancel may only produce out/leave. Cancel adds the abort signal first.

Example 5 — Log pointerId and Type

Identify which pointer was cancelled.

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

stage.addEventListener("pointercancel", (event) => {
  out.textContent =
    "cancel id=" + event.pointerId +
    " type=" + event.pointerType +
    " primary=" + event.isPrimary;
});
Try It Yourself

How It Works

Multi-touch UIs should key session state by pointerId so one cancel does not wipe every finger.

🚀 Common Use Cases

  • Abort drag / resize / draw sessions when the OS steals the gesture.
  • Reset pressed styles if touch-action lets the page scroll instead.
  • Clear capture-related UI alongside lostpointercapture.
  • Handle palm rejection and multi-pointer limits cleanly.
  • Teach Pointer Events end paths beyond a simple pointerup.

🔧 How It Works

1

pointerdown

A pointer becomes active; your app may start a gesture.

Start
2

Interrupt

Browser or OS decides the pointer cannot continue.

Cause
3

pointercancel

Abort signal; clear drag/draw state for that pointerId.

Event
4

pointerout → pointerleave

MDN follow-up leave sequence after cancel.

📝 Notes

  • MDN: Baseline Widely available (since July 2020) — no Deprecated / Experimental / Non-standard banner.
  • Always clear gesture state on pointercancel as well as pointerup.
  • After cancel, expect pointerout then pointerleave.
  • touch-action can cause the browser to take over scrolling/zooming and cancel your pointer.
  • Related learning: lostpointercapture, gotpointercapture, paste, addEventListener(), JavaScript hub.

Browser Support

pointercancel is marked Baseline Widely available on MDN (since July 2020). Logos use the shared browser-image-sprite.png sprite from this project. Pointer Events are the modern unified mouse/touch/pen model across engines.

Baseline · Widely available

Element pointercancel

Fires when the browser aborts a pointer; clear gesture state, then expect pointerout / pointerleave.

Full Widely available
Google Chrome Full support
Yes
Mozilla Firefox Full support
Yes
Apple Safari Full support
Yes
Microsoft Edge Full support
Yes
Opera Full support
Yes
Internet Explorer Pointer Events (legacy IE11 path)
Partial
pointercancel Baseline

Bottom line: Wire cancel cleanup next to pointerup for robust drag and drawing UIs on touch devices.

Conclusion

pointercancel is the abort path for Pointer Events. Listen beside pointerup, clear session state by pointerId, and remember the follow-up pointerout / pointerleave sequence.

Continue with pointerdown, lostpointercapture, gotpointercapture, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Clear drag/draw state on both pointerup and pointercancel
  • Key multi-touch sessions by pointerId
  • Use touch-action intentionally when you need exclusive gestures
  • Pair capture APIs with lostpointercapture cleanup
  • Prefer addEventListener in production code

❌ Don’t

  • Assume every gesture ends with pointerup
  • Leave pressed / dragging CSS classes after a cancel
  • Ignore palm rejection and multi-pointer cancel paths on touch devices
  • Forget that cancel is followed by out/leave
  • Overwrite onpointercancel if you need multiple listeners

Key Takeaways

Knowledge Unlocked

Five things to remember about pointercancel

Pointer aborted—clear gesture state before the leave sequence.

5
Core concepts
📄02

PointerEvent

pointerId · type

API
🔄03

Cleanup

with pointerup

Pattern
👆04

Then leave

out → leave

Sequence
🎯05

Baseline

since Jul 2020

Status

❓ Frequently Asked Questions

It fires when the browser decides there will likely be no more events for that pointer, or when after pointerdown the pointer is used to pan, zoom, or scroll the viewport. Use it to abort in-progress gestures cleanly.
No. MDN marks Element pointercancel as Baseline Widely available (since July 2020). It is not Deprecated, Experimental, or Non-standard.
A PointerEvent (inherits from MouseEvent and Event). Useful fields include pointerId, pointerType, isPrimary, pressure, and width/height.
MDN notes the browser also sends pointerout followed by pointerleave after pointercancel.
Whenever you start a drag, draw, or press-and-hold session on pointerdown. Cancel resets UI if the OS steals the gesture (home button, app switcher, orientation change, palm rejection, touch-action scroll, too many pointers).
If you used setPointerCapture, a cancel path often ends capture and can fire lostpointercapture too. Always clear drag state on pointercancel and/or lostpointercapture so the UI never sticks.
Did you know?

Even after a pointercancel, MDN says the browser still dispatches pointerout and pointerleave. That means leave handlers can still run—so keep cancel cleanup idempotent (safe to call twice).

Next: pointerdown

Learn the PointerEvent that fires when a pointer becomes active.

pointerdown →

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