Favorites

DOM CustomEvent Interface

☕
Enjoying this site?

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

Buy us a coffee
CustomEvent
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

CustomEvent lets you create your own events with extra data in a detail property, and dispatch them on any element or EventTarget.

Description

The CustomEvent interface represents an event created by your own code, carrying any data you like in its detail property. Create one with new CustomEvent(type, options) and send it with dispatchEvent(); listeners are added with addEventListener() as for built-in events.

Custom events let separate parts of an application, or web components, communicate without knowing about each other. Set bubbles: true if ancestors should be able to listen for it.

The detail value is passed by reference, so listeners receive the same object; avoid changing it in one listener if others also use it. Event names for custom events can be any string, but using a prefix or namespace, such as "cart:add", helps avoid clashes with built-in events and other libraries. Setting cancelable: true lets listeners call preventDefault(), and dispatchEvent() then returns false so the sender can react.

Inheritance

CustomEvent inherits properties and methods from Event.

Properties

NameDescription
CustomEvent.detailThe detail property of a CustomEvent holds the data passed when the event was created.

Example

<div id="cart">Cart</div>
const cart = document.getElementById('cart');
document.addEventListener('cart:add', e => {
  console.log('Added', e.detail.item, 'x', e.detail.qty);
});
cart.dispatchEvent(new CustomEvent('cart:add', {
  detail: { item: 'Mug', qty: 2 },
  bubbles: true,
}));

Browser Support

The following information will show you the current browser support for the CustomEvent interface. Hover over a browser icon to see the version that first introduced support for this interface.

This interface 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