Element.slot is an instance property that reflects the HTML slot attribute. It returns the name of the shadow DOM slot the element is assigned to—or an empty string when no named slot is set. Learn reading, writing, and pairing it with <slot> in web components—with five examples and try-it labs.
01
Kind
Instance property
02
Access
Read / write
03
Type
String
04
Reflects
slot attribute
05
Empty
No named slot
06
Status
Baseline widely
Fundamentals
Introduction
Web components often use slots as placeholders inside a shadow tree. Page authors fill those placeholders by placing light-DOM children into the host and giving them a slot attribute that matches a named <slot>.
element.slot is the JavaScript view of that attribute: it tells you which named slot the element targets, and you can change it at runtime.
JavaScript
const el = document.createElement("span");
el.slot = "my-text";
console.log(el.slot); // "my-text"
💡
Beginner tip
Think of slot as a mailing label. The shadow tree has named mailboxes (<slot name="...">). Light-DOM children use slot="..." to choose which mailbox they go into.
Concept
Understanding the Property
MDN: the slot property of the Element interface returns the name of the shadow DOM slot the element is inserted in. A slot is a placeholder inside a web component that users can fill with their own markup.
String value — the named slot, or "" when unset.
Reflects the attribute — el.slot and slot="..." stay in sync.
Read and write — you can get or set the name from JavaScript.
Pairs with <slot> — useful for custom elements and templates.
Foundation
📝 Syntax
JavaScript
element.slot
element.slot = "slot-name"
Value
A string: the name of the assigned shadow DOM slot, or an empty string when the element is not assigned to a named slot.
Item
Detail
Type
string
Access
Read / write
Reflects
HTML slot attribute
Named slot
e.g. "my-text"
Unset
"" (empty string)
⚠️
Not the <slot> element
element.slot is a string name on slotted content. The placeholder itself is an HTMLSlotElement created with <slot> inside the shadow tree.
Pattern
📋 Named Slot Pattern
MDN’s core idea: put a named <slot> in the shadow tree, then assign light-DOM children with a matching slot name. Reading element.slot returns that name.
JavaScript
// Light DOM child targeting a named slot
const span = document.createElement("span");
span.slot = "my-text";
span.textContent = "Let's have some different text!";
// Later:
console.log(span.slot); // "my-text"
Related learning: shadowRoot, part, and HTML <slot> / HTMLSlotElement.
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Read slot name
el.slot
Set slot name
el.slot = "title"
HTML equivalent
<span slot="title">
Clear named slot
el.slot = ""
Shadow placeholder
<slot name="title">
MDN status
Baseline Widely available
Snapshot
🔍 At a Glance
Four facts about Element.slot.
Kind
get / set
Instance
Type
string
Slot name
Reflects
slot attr
HTML
Baseline
widely
Shadow DOM
Hands-On
Examples Gallery
Examples follow MDN Element: slot and show reading, writing, and using named slots with a simple host.
📚 Getting Started
Read the slot name from markup and from an unset element.
Example 1 — Read a Named Slot
An element with slot="my-text" reports that name in JavaScript.
The shadow <slot name="my-text"> and the child’s slot property must match for content to project into that placeholder.
Example 5 — Support Snapshot
Feature-detect and remember the string / empty rules.
JavaScript
console.log({
supported: "slot" in Element.prototype,
returns: "string (slot name or \"\")",
tip: "Reflects the HTML slot attribute",
status: "Baseline Widely available (MDN)"
});
Element.slot is Baseline Widely available (MDN). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Element.slot
Read / write — returns the named shadow DOM slot string (or empty).
BaselineWidely available
Google ChromeSupported
Yes
Microsoft EdgeSupported
Yes
Mozilla FirefoxSupported
Yes
Apple SafariSupported
Yes
OperaSupported
Yes
Internet ExplorerNot supported
No
slotBaseline
Bottom line: Use element.slot to read or set which named shadow DOM slot a light-DOM child targets.
Wrap Up
Conclusion
slot is the string property that connects light-DOM content to named <slot> placeholders in a shadow tree. Read it to inspect assignment; write it to move content between slots.
Confuse element.slot with the <slot> element itself
Expect a non-empty string for default (unnamed) slots
Use mismatched names between attribute and <slot name>
Treat slot as a DOM node reference
Skip documenting which slots your custom element supports
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about slot
Read/write string that names which shadow DOM slot an element targets.
5
Core concepts
📄01
Get / set
on Element
Kind
📝02
string
slot name
Type
🔍03
"" when unset
default path
Empty
✅04
Baseline
widely available
Status
🎯05
Match names
to <slot>
Tip
❓ Frequently Asked Questions
It returns the name of the shadow DOM slot the element is assigned to. It reflects the HTML slot attribute as a string.
No. MDN marks Element.slot as Baseline Widely available. It is not Deprecated, Experimental, or Non-standard.
An empty string means the element is not assigned to a named slot (it may still fall into the default unnamed slot).
No. You can read and write element.slot. Setting it updates the matching slot attribute.
Inside a shadow tree you place <slot name="title">. Light-DOM children with slot="title" fill that named slot. element.slot then returns "title".
No. Element.slot is a string property on slotted content. <slot> elements are HTMLSlotElement instances inside the shadow tree.
Did you know?
MDN’s classic demo uses a custom element with a shadow slot named my-text. Reading document.querySelector("my-paragraph span").slot logs "my-text"—the same idea as Example 1 and Example 4 on this page.