HTMLSlotElement

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

The HTMLSlotElement interface of the Shadow DOM API enables access to the name and assigned nodes of an HTML <slot> element.

EventTarget Node Element HTMLElement HTMLSlotElement

Instance properties

Also inherits properties from its parent interface, HTMLElement.

HTMLSlotElement.name

A string used to get and set the slot's name.

Instance methods

Also inherits methods from its parent interface, HTMLElement.

HTMLSlotElement.assign()

Sets the manually assigned nodes for this slot to the given nodes.

HTMLSlotElement.assignedNodes()

Returns a sequence of the nodes assigned to this slot. If the flatten option is set to true, it returns a sequence of both the nodes assigned to this slot, and the nodes assigned to any other slots that are descendants of this slot. If no assigned nodes are found, it returns the slot's fallback content.

HTMLSlotElement.assignedElements()

Returns a sequence of the elements assigned to this slot (and no other nodes). If the flatten option is set to true, it returns a sequence of both the elements assigned to this slot, and the elements assigned to any other slots that are descendants of this slot. If no assigned elements are found, it returns the slot's fallback content.

Events

Also inherits events from its parent interface, HTMLElement.

Listen to these events using addEventListener() or by assigning an event listener to the oneventname property of this interface.

slotchange

Fired on an HTMLSlotElement instance (<slot> element) when the node(s) contained in that slot change.

Examples

The following snippet is taken from our slotchange example (see it live also).

js
let slots = this.shadowRoot.querySelectorAll("slot");
slots[1].addEventListener("slotchange", (e) => {
  let nodes = slots[1].assignedNodes();
  console.log(
    `Element in Slot "${slots[1].name}" changed to "${nodes[0].outerHTML}".`,
  );
});

Here we grab references to all the slots, then add a slotchange event listener to the 2nd slot in the template — which is the one that keeps having its contents changed in the example.

Every time the element inserted in the slot changes, we log a report to the console saying which slot has changed, and what the new node inside the slot is.

Specifications

Specification
HTML
# htmlslotelement

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
HTMLSlotElement
Chrome – Full support
Chrome 53 (Release date: 2016-08-31)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote Full support
Opera – Full support
Opera 40 (Release date: 2016-09-20)
footnote Full support
Safari – Full support
Safari 10 (Release date: 2016-09-20)
footnote Full support
Chrome Android – Full support
Chrome Android 53 (Release date: 2016-09-07)
footnote Full support
Firefox for Android – Full support
Firefox for Android 63 (Release date: 2018-10-23)
footnote Full support
Opera Android – Full support
Opera Android 41 (Release date: 2016-10-25)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10 (Release date: 2016-09-13)
footnote Full support
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote Full support
WebView Android – Full support
WebView Android 53 (Release date: 2016-09-07)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10 (Release date: 2016-09-13)
footnote Full support
assign
Chrome – Partial support
Chrome 86 – 91 (Release date: 2020-10-20)
footnote Partial support
footnote Accepted sequence<Node> instead of (Element or Text)....
Chrome – Full support
Chrome 92 (Release date: 2021-07-20)
footnote
footnote Before Chrome 95, the method accepted any Node instead of just Element and Text.
Edge – Partial support
Edge 86 – 91 (Release date: 2020-10-09)
footnote Partial support
footnote Accepted sequence<Node> instead of (Element or Text)....
Edge – Full support
Edge 92 (Release date: 2021-07-22)
footnote
footnote Before Edge 95, the method accepted any Node instead of just Element and Text.
Firefox – Full support
Firefox 92 (Release date: 2021-09-07)
footnote Full support
Opera – Partial support
Opera 72 – 77 (Release date: 2020-10-21)
footnote Partial support
footnote Accepted sequence<Node> instead of (Element or Text)....
Opera – Full support
Opera 78 (Release date: 2021-08-03)
footnote
footnote Before Opera 81, the method accepted any Node instead of just Element and Text.
Safari – Full support
Safari 16.4 (Release date: 2023-03-27)
footnote Full support
Chrome Android – Partial support
Chrome Android 86 – 91 (Release date: 2020-10-20)
footnote Partial support
footnote Accepted sequence<Node> instead of (Element or Text)....
Chrome Android – Full support
Chrome Android 92 (Release date: 2021-07-20)
footnote
footnote Before Chrome Android 95, the method accepted any Node instead of just Element and Text.
Firefox for Android – Full support
Firefox for Android 92 (Release date: 2021-09-07)
footnote Full support
Opera Android – Partial support
Opera Android 61 – 64 (Release date: 2020-12-07)
footnote Partial support
footnote Accepted sequence<Node> instead of (Element or Text)....
Opera Android – Full support
Opera Android 65 (Release date: 2021-10-20)
footnote
footnote Before Opera Android 67, the method accepted any Node instead of just Element and Text.
Safari on iOS – Full support
Safari on iOS 16.4 (Release date: 2023-03-27)
footnote Full support
Samsung Internet – Partial support
Samsung Internet 14 – 15 (Release date: 2021-04-17)
footnote Partial support
footnote Accepted sequence<Node> instead of (Element or Text)....
Samsung Internet – Full support
Samsung Internet 16 (Release date: 2021-11-25)
footnote
footnote Before Samsung Internet 17.0, the method accepted any Node instead of just Element and Text.
WebView Android – Partial support
WebView Android 86 – 91 (Release date: 2020-10-20)
footnote Partial support
footnote Accepted sequence<Node> instead of (Element or Text)....
WebView Android – Full support
WebView Android 92 (Release date: 2021-07-20)
footnote
footnote Before WebView Android 95, the method accepted any Node instead of just Element and Text.
WebView on iOS – Full support
WebView on iOS 16.4 (Release date: 2023-03-27)
footnote Full support
assignedElements
Chrome – Full support
Chrome 65 (Release date: 2018-03-06)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 66 (Release date: 2019-03-19)
footnote Full support
Opera – Full support
Opera 52 (Release date: 2018-03-22)
footnote Full support
Safari – Full support
Safari 12.1 (Release date: 2019-03-25)
footnote Full support
Chrome Android – Full support
Chrome Android 65 (Release date: 2018-03-06)
footnote Full support
Firefox for Android – Full support
Firefox for Android 66 (Release date: 2019-03-19)
footnote Full support
Opera Android – Full support
Opera Android 47 (Release date: 2018-07-23)
footnote Full support
Safari on iOS – Full support
Safari on iOS 12.2 (Release date: 2019-03-25)
footnote Full support
Samsung Internet – Full support
Samsung Internet 9 (Release date: 2018-09-15)
footnote Full support
WebView Android – Full support
WebView Android 65 (Release date: 2018-03-06)
footnote Full support
WebView on iOS – Full support
WebView on iOS 12.2 (Release date: 2019-03-25)
footnote Full support
assignedNodes
Chrome – Full support
Chrome 53 (Release date: 2016-08-31)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote Full support
Opera – Full support
Opera 40 (Release date: 2016-09-20)
footnote Full support
Safari – Full support
Safari 10 (Release date: 2016-09-20)
footnote Full support
Chrome Android – Full support
Chrome Android 53 (Release date: 2016-09-07)
footnote Full support
Firefox for Android – Full support
Firefox for Android 63 (Release date: 2018-10-23)
footnote Full support
Opera Android – Full support
Opera Android 41 (Release date: 2016-10-25)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10 (Release date: 2016-09-13)
footnote Full support
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote Full support
WebView Android – Full support
WebView Android 53 (Release date: 2016-09-07)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10 (Release date: 2016-09-13)
footnote Full support
name
Chrome – Full support
Chrome 53 (Release date: 2016-08-31)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote Full support
Opera – Full support
Opera 40 (Release date: 2016-09-20)
footnote Full support
Safari – Full support
Safari 10 (Release date: 2016-09-20)
footnote Full support
Chrome Android – Full support
Chrome Android 53 (Release date: 2016-09-07)
footnote Full support
Firefox for Android – Full support
Firefox for Android 63 (Release date: 2018-10-23)
footnote Full support
Opera Android – Full support
Opera Android 41 (Release date: 2016-10-25)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10 (Release date: 2016-09-13)
footnote Full support
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote Full support
WebView Android – Full support
WebView Android 53 (Release date: 2016-09-07)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10 (Release date: 2016-09-13)
footnote Full support
slotchange event
Chrome – Full support
Chrome 53 (Release date: 2016-08-31)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote Full support
Opera – Full support
Opera 40 (Release date: 2016-09-20)
footnote Full support
Safari – Partial support
Safari 10 – 10 (Release date: 2016-09-20)
footnote Partial support
footnote The onslotchange event handler property is not supported.
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote Full support
Chrome Android – Full support
Chrome Android 53 (Release date: 2016-09-07)
footnote Full support
Firefox for Android – Full support
Firefox for Android 63 (Release date: 2018-10-23)
footnote Full support
Opera Android – Full support
Opera Android 41 (Release date: 2016-10-25)
footnote Full support
Safari on iOS – Partial support
Safari on iOS 10 – 10 (Release date: 2016-09-13)
footnote Partial support
footnote The onslotchange event handler property is not supported.
Safari on iOS – Full support
Safari on iOS 10.3 (Release date: 2017-03-27)
footnote Full support
Samsung Internet – Full support
Samsung Internet 6 (Release date: 2017-08-23)
footnote Full support
WebView Android – Full support
WebView Android 53 (Release date: 2016-09-07)
footnote Full support
WebView on iOS – Partial support
WebView on iOS 10 – 10 (Release date: 2016-09-13)
footnote Partial support
footnote The onslotchange event handler property is not supported.
WebView on iOS – Full support
WebView on iOS 10.3 (Release date: 2017-03-27)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
See implementation notes.
Has more compatibility info.