CKTIS / HTML
slot — assigning an element to a Shadow DOM slot
The global slot attribute selects a named slot in Shadow DOM where an element is presented. Its value corresponds to the slot element's name value; the attribute and the element have different roles.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
slot="name"The slot attribute is allowed on all HTML elements. With ordinary name-based assignment, it selects where an element is presented in its parent's Shadow DOM. The attribute alone creates neither a shadow tree nor a content insertion point.
Do not confuse the slot attribute on the supplied element with the slot element inside the shadow tree. The former selects a name; the latter defines a destination with that name through name. Values must match exactly, including case. The assigned element must be a direct child of the host; placing the attribute on an arbitrary deeper descendant is insufficient.
An omitted attribute or slot="" selects the default slot, which is an unnamed slot. An unmatched name does not fall back to the default slot. Fallback content inside a slot element is presented when no nodes are assigned to it. Assignment does not move the element in the DOM tree.
In the example, span remains a child of host but is presented at the slot with name="label". The expected page text is Label: Hello. After changing to slot="other", the expected text is Label: Fallback.
Examples
<!doctype html>
<meta charset="utf-8">
<title>slot demo</title>
<div id="host"><span slot="label">Hello</span></div>
<script>
const host = document.getElementById('host');
const root = host.attachShadow({ mode: 'open' });
root.innerHTML = '<p>Label: <slot name="label">Fallback</slot></p>';
</script>Result
Label: Hello
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.