event.preventDefault() tells the browser not to run the event’s default action(MDN) — such as following a link, submitting a form, or toggling a checkbox. Propagation continues unless you also stop it.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call event.preventDefault. Start with this line.
JavaScript
event.preventDefault()
Call
What it does
event.preventDefault()
Primary signature.
event.preventDefault(...)
Call with the arguments your case needs.
Built into the browser. Call preventDefault(...) on an Event instance — no import required.
Library declarations
JavaScript
event.preventDefault()
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
undefined
JavaScript Examples
Example 1 — Block Checkbox Toggle
Classic MDN pattern: click still fires; check state does not change.
JavaScript
const checkbox = document.querySelector("#id-checkbox");
checkbox.addEventListener("click", (event) => {
console.log("click heard — but no toggle");
event.preventDefault();
});
Child cancels default. Browser skips its default action.
Event still bubbles. Parent listener runs.
Different job. Use stopPropagation to stop travel.
Pick the right tool. Default vs path are separate concerns.
Compatibility
Browser Support
Event.preventDefault() is marked Baseline Widely available on MDN (since July 2015). It is also available in Web Workers.
✓ Baseline · Widely available
Event.preventDefault()
Cancels the browser default action when the event is cancelable. Does not stop propagation. Passive listeners cannot cancel.
100%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
preventDefault()Excellent
Bottom line: Safe everyday API. Check cancelable / avoid passive listeners when you must cancel. See the MDN preventDefault reference.
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). Check cancelable first when unsure. A passive listener that calls preventDefault may also log a console warning.
After a successful cancel, event.defaultPrevented is true. For synthetic cancelable events you dispatch, dispatchEvent() returns false when preventDefault was called.
Sometimes yes. MDN suggests disabled/readonly on controls, HTML constraint validation, or CSS overflow when a declarative option fits better than fighting defaults in JavaScript.