Favorites

HTML onslotchange Event Attribute

☕
Enjoying this site?

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

Buy us a coffee
onslotchange
HTML Event AttributeThis event attribute is supported by all modern browsers.
Updated 22nd November 2026

Description

The onslotchange event attribute runs a script when the nodes assigned to a <slot> element change, that is, when elements are added to or removed from the light DOM of a web component, or their slot attribute changes, so that different content is shown in the slot.

It is used inside the shadow root of a custom element. In the handler, event.target.assignedNodes() or assignedElements() returns the new content. It does not fire when the children of a slotted element change, only when the set of slotted nodes changes. The event bubbles, but it does not cross the shadow boundary.

Syntax

<slot onslotchange="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html>
<html>
<head>
<title>onslotchange event</title>
</head>
<body>
<div id="host">
<template shadowrootmode="open">
<p>Slot content:</p>
<slot onslotchange="this.getRootNode().host.nextElementSibling.textContent = 'slotchange: ' + this.assignedElements().length + ' element(s)'"></slot>
</template>
<span>First item</span>
</div>
<p></p>
<button onclick="var s = document.createElement('span'); s.textContent = ' New item'; document.getElementById('host').appendChild(s)">Add item</button>
</body>
</html>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML onslotchange event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.

This event attribute 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