JavaScript Event cancelable Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

The cancelable property is a read-only boolean on every Event: true if preventDefault() can cancel the event’s default action, false if it cannot. Learn how to read it, set it on synthetic events, check before calling preventDefault, and relate it to defaultPrevented—with five examples and try-it labs.

01

Kind

Instance property

02

Type

boolean (read-only)

03

Means

Can preventDefault?

04

Set via

Constructor options

05

Workers

Yes

06

Status

Baseline widely

Introduction

Many browser events have a default action: follow a link, submit a form, scroll on wheel, leave the page on beforeunload. event.cancelable tells you whether your listener is allowed to block that default with preventDefault().

If cancelable is false, calling preventDefault() does nothing useful—the default still happens. Most cancelable browser events come from user interaction. Synthetic events choose cancelability when created.

💡
Beginner tip

Canceling is not the same as stopping propagation. preventDefault() blocks the browser default; stopPropagation() stops travel through the DOM. Check cancelable before preventDefault() in shared handlers.

Understanding Event.cancelable

An instance property that answers: “Can preventDefault() cancel this event’s default action?”

  • Valuetrue if cancelable; false otherwise.
  • Read-only — set only at construction for synthetic events.
  • Cancel how — call event.preventDefault() when cancelable is true.
  • After cancelevent.defaultPrevented becomes true.
  • Baseline Widely available on MDN (since July 2015); also in Web Workers.

📝 Syntax

JavaScript
event.cancelable

Value

A boolean: true if the event can be canceled.

Set on synthetic events

JavaScript
const soft = new Event("save"); // default cancelable: false
const hard = new Event("save", { cancelable: true });

console.log(soft.cancelable); // false
console.log(hard.cancelable); // true

⚡ Quick Reference

GoalCode / note
Readevent.cancelable
Create cancelable eventnew Event("x", { cancelable: true })
Default for new Eventcancelable: false
Cancel safelyif (event.cancelable) event.preventDefault()
Check resultevent.defaultPrevented
MDN statusBaseline Widely available (since July 2015)

🔍 At a Glance

Four facts to remember about Event.cancelable.

Type
boolean

Read-only

true means
can cancel

preventDefault OK

Set how?
options

At construction

Baseline
widely

Since July 2015

Examples Gallery

Examples follow MDN Event: cancelable. Use View Output or Try It Yourself.

📚 Getting Started

Read the flag and set it on synthetic events.

Example 1 — Read cancelable on a Click

Clicks are cancelable—log the property when the user clicks.

JavaScript
document.getElementById("btn").addEventListener("click", (event) => {
  console.log("cancelable =", event.cancelable); // true for click
});
Try It Yourself

How It Works

Built-in click events are cancelable, so you can call preventDefault() when needed.

Example 2 — cancelable: true vs Default

Compare two synthetic events with different options.

JavaScript
const a = new Event("save"); // default cancelable: false
const b = new Event("save", { cancelable: true });

console.log(a.cancelable); // false
console.log(b.cancelable); // true
Try It Yourself

How It Works

The property is fixed when the event is constructed; you cannot flip it later.

📈 Canceling Defaults Safely

preventDefault, MDN’s wheel guard, and canceling a link navigation.

Example 3 — preventDefault + defaultPrevented

Cancel a cancelable synthetic event and check the result.

JavaScript
const target = new EventTarget();

target.addEventListener("save", (event) => {
  if (event.cancelable) {
    event.preventDefault();
  }
  console.log("defaultPrevented =", event.defaultPrevented);
});

target.dispatchEvent(new Event("save", { cancelable: true }));
// โ†’ defaultPrevented = true
Try It Yourself

How It Works

dispatchEvent returns false when the default was prevented on a cancelable event.

Example 4 — Check Before preventDefault (MDN)

MDN wheel pattern: only call preventDefault when the event is cancelable.

JavaScript
function preventScrollWheel(event) {
  if (typeof event.cancelable !== "boolean" || event.cancelable) {
    // The event can be canceled, so we do so.
    event.preventDefault();
  } else {
    // Not safe to call preventDefault()
    console.warn("The following event couldn't be canceled:");
    console.dir(event);
  }
}

document.addEventListener("wheel", preventScrollWheel, { passive: false });
Try It Yourself

How It Works

MDN notes some browsers may only cancel the first wheel in a sequence. Always check cancelable in shared handlers. Use { passive: false } when you need to cancel wheel.

🚀 Common Use Cases

  • Blocking form submit or link navigation after validation fails.
  • Custom zoom / scroll UIs that cancel wheel when allowed.
  • Shared listeners that handle many event types safely.
  • Synthetic app events that callers may cancel via preventDefault.
  • Confirming leave-page flows with cancelable beforeunload patterns.

🔧 How It Works

1

Event is created

Browser or new Event(type, { cancelable }) sets the flag.

Setup
2

Listener runs

Your handler reads event.cancelable.

Check
3

Optional preventDefault

If cancelable, call preventDefault() to block the default.

Cancel
4

Default skipped or kept

defaultPrevented reflects whether the cancel stuck.

📝 Notes

  • MDN: Baseline Widely available (since July 2015) — no Deprecated / Experimental / Non-standard banner.
  • Available in Web Workers.
  • Read-only—set via constructor options for synthetic events.
  • Passive listeners cannot cancel (for example wheel with { passive: true }).
  • Related learning: bubbles, Event(), wheel, addEventListener(), JavaScript hub.

Universal Browser Support

Event.cancelable is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. It is also available in Web Workers.

Baseline · Widely available

Event.cancelable

Read-only boolean: true if preventDefault() can cancel the eventโ€™s default action.

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported (legacy)
Full support
Event.cancelable Excellent

Bottom line: Read event.cancelable before preventDefault() in shared handlers. Set cancelable only when constructing synthetic events.

Conclusion

Event.cancelable is the yes/no for whether preventDefault() can block the default action. Read it on any event; set it only when you construct a synthetic one with { cancelable: true }.

Continue with cancelBubble, bubbles, Event(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Check event.cancelable before preventDefault() in shared handlers
  • Pass { cancelable: true } when callers may cancel custom events
  • Use { passive: false } when you must cancel wheel / touch scroll
  • Read defaultPrevented to confirm a cancel stuck
  • Learn bubbles as a separate propagation flag

❌ Don’t

  • Assign event.cancelable = true after creation
  • Assume every event type is cancelable
  • Confuse preventDefault with stopPropagation
  • Forget that default new Event() uses cancelable: false
  • Expect passive listeners to allow canceling

Key Takeaways

Knowledge Unlocked

Five things to remember about cancelable

Read-only flag for whether preventDefault can win.

5
Core concepts
02

true

preventDefault OK

Meaning
📝03

Set once

constructor options

Create
🛡️04

Check first

especially wheel

Safety
🎯05

Baseline

since Jul 2015

Status

❓ Frequently Asked Questions

It is a read-only boolean on an Event. It is true if the event can be canceled with preventDefault(), so the browser does not run its default action. If it is false, preventDefault() cannot stop that default.
No. MDN marks Event.cancelable as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is also available in Web Workers.
Call event.preventDefault() in a listener. That only works when event.cancelable is true. After a successful cancel, event.defaultPrevented becomes true.
No. cancelable is read-only. For synthetic events, set it with new Event(type, { cancelable: true }). Built-in events get their value from the browser.
MDN notes that some events (for example later wheel events in a sequence) may not be cancelable. Handlers that cover many event types should check cancelable before calling preventDefault().
No. bubbles controls whether the event travels up the DOM. cancelable controls whether preventDefault() can block the default action. They are independent flags.
Did you know?

MDN calls out wheel: some browsers may only allow canceling the first wheel event in a sequence. Later ones can report cancelable === false—another reason to check before preventDefault().

Next: cancelBubble

Learn the deprecated flag and migrate to stopPropagation.

cancelBubble →

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