HTML4 HTML5
The <slot> tag is a special element in Web Components technology (Shadow DOM)[cite: 3]. It acts as a placeholder inside a component template where custom external HTML content can be injected[cite: 3].
This allows creating flexible, reusable components with fixed internal structures whose specific sections (e.g., header or footer) can be modified externally[cite: 3].
Both opening and closing tags are mandatory[cite: 3].
Attributes:
name – assigns a unique name to the slot, allowing specific HTML elements to be injected into matching named slots inside the component[cite: 3].class, id, and style are also used[cite: 3].In the example below, a card component template defines a <slot> with attribute name="card-text" for custom text[cite: 3]. If no content is provided, default fallback text inside the slot is shown[cite: 3]:
Code:
The browser will interpret this template and its slots (when rendered in a component) as follows[cite: 3]:
In this example, the component features two slots: title and footer[cite: 3]. We inject a custom title into the first slot, while the second remains empty, rendering its default content[cite: 3]:
Code:
The browser will interpret this structure as follows (header replaced by custom text, footer keeps default text)[cite: 3]: