The preventDefault() method tells the browser not to run the default action for an event—following a link, submitting a form, toggling a checkbox, and more. Learn how it pairs with cancelable and defaultPrevented, and when it has no effect—with five examples and try-it labs.
01
Kind
Instance method
02
Returns
undefined
03
Params
None
04
Needs
cancelable
05
Sets
defaultPrevented
06
Status
Baseline widely
Fundamentals
Introduction
Many events have a default action built into the browser. Clicking an <a href> navigates. Submitting a form sends data. Clicking a checkbox toggles it. Sometimes you want to handle the interaction yourself in JavaScript instead.
Call event.preventDefault() inside a listener. The event still bubbles (unless you stop it), but the browser skips that default behavior. If the event is not cancelable, the call does nothing.
💡
Beginner tip
preventDefault() ≠ stopPropagation(). One cancels the browser’s built-in action; the other stops the event from reaching other listeners up or down the tree.
Concept
Understanding Event.preventDefault()
An instance method that cancels the event’s default action when the event is cancelable.
No parameters — call event.preventDefault().
Return value — none (undefined).
Requires cancelable — if event.cancelable is false, nothing happens.
Sets defaultPrevented — becomes true after a successful cancel.
Does not stop propagation — other listeners still run unless you stop them.
Passive listeners — calling it may be ignored and warn in the console.
Baseline Widely available on MDN (since July 2015); also in Web Workers.
Event.preventDefault() 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.preventDefault()
Cancels the browser default action when the event is cancelable.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported in legacy IE (prefer modern browsers)
Legacy
Event.preventDefault()Excellent
Bottom line: Use preventDefault() to cancel defaults; check cancelable and read defaultPrevented when you need certainty.
Wrap Up
Conclusion
Event.preventDefault() cancels the browser’s default action for a cancelable event. It does not stop propagation by itself—pair it with cancelable and defaultPrevented for clear, reliable handlers.
Listen to submit for forms (not only button click)
Keep real hrefs for accessibility when blocking nav
Prefer HTML attributes when they replace JS fights
❌ Don’t
Expect it to stop bubbling (use stopPropagation)
Rely on it inside passive listeners
Assume every synthetic event is cancelable
Confuse it with deprecated returnValue = false
Block defaults without a clear alternate UX
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about preventDefault()
Cancel defaults—not the event path.
5
Core concepts
🚫01
Cancels
default action
API
✅02
Needs
cancelable
Guard
📈03
Sets
defaultPrevented
Flag
🔁04
Bubbles
still continue
Flow
🎯05
Baseline
since Jul 2015
Status
❓ Frequently Asked Questions
It tells the browser not to run the event's default action—such as following a link, submitting a form, checking a checkbox, or scrolling—while the event still propagates unless you also stop propagation.
No. MDN marks Event.preventDefault() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is also available in Web Workers.
No. preventDefault() only cancels the default action. The event still travels through capture/bubble unless you call stopPropagation() or stopImmediatePropagation().
If event.cancelable is false, or if the listener is passive (common for touchmove/wheel on the document). Check cancelable first when unsure.
After a successful cancel, event.defaultPrevented is true. For synthetic events you dispatch, dispatchEvent() returns false when preventDefault was called on a cancelable event.
Sometimes yes. MDN suggests disabled/readonly on controls, HTML constraint validation, or CSS overflow to avoid fighting defaults with JavaScript when a declarative option fits.
Did you know?
For cancelable synthetic events, target.dispatchEvent(event) returns false if a listener called preventDefault()—a handy signal when you fire your own events and need to know whether they were canceled.