Favorites

DOM Event.preventDefault() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Event.preventDefault()
DOM Event MethodThis method is supported by all modern browsers.
Updated 28th November 2026

The preventDefault() method stops the browser's default action for an event, such as following a link or submitting a form.

Description

The preventDefault() method tells the browser not to perform the event's default action: following a link, submitting a form, ticking a checkbox, typing a character, opening the context menu and so on. The event still propagates normally; use stopPropagation() to stop that. It only works on cancelable events, which defaultPrevented reports afterwards.

It has no effect in listeners added with { passive: true }.

Some default actions can't be prevented, such as closing the browser tab; the beforeunload event can only show a generic confirmation. Calling preventDefault() on keydown stops typing and browser shortcuts, so only do it for the specific keys you handle.

Syntax

event.preventDefault()

Return Value

None (undefined).

Example

<a href="https://example.com">External link</a>
<form><button>Send</button></form>
document.querySelector('a').addEventListener('click', e => {
  e.preventDefault();
  console.log('Link not followed; defaultPrevented =', e.defaultPrevented);
});
document.querySelector('form').addEventListener('submit', e => {
  e.preventDefault();
  console.log('Form handled with JavaScript instead');
});
document.querySelector('a').click();
document.querySelector('form').requestSubmit();

Browser Support

The following information will show you the current browser support for the Event.preventDefault() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee