Element.assignedSlot is a read-only instance property that returns the HTMLSlotElement an element is inserted into. Learn how Shadow DOM slots work, when the value is null, and how to inspect assignment from JavaScript—with five examples and try-it labs.
01
Kind
Instance property
02
Access
Read-only
03
Type
HTMLSlotElement | null
04
Topic
Shadow DOM slots
05
Status
Baseline widely
06
Needs
Open shadow root
Fundamentals
Introduction
Custom elements often use slots as placeholders inside a shadow tree. Light-DOM children with a matching slot attribute appear in those placeholders when the page renders.
From a slotted child, assignedSlot answers: “Which <slot> am I assigned to?” That is useful for debugging layouts and building slot-aware components.
Think of <slot> as a hole in the component’s shadow template, and slot="name" on a child as the key that fills that hole.
Concept
Understanding the Property
MDN: the assignedSlot property of the Element interface returns an HTMLSlotElement representing the <slot> the node is inserted in.
Read-only — you inspect assignment; you do not set this property.
Slottable child — works on light-DOM content assigned into a slot.
May be null — not slotted, or shadow root is closed.
Baseline — widely available since January 2020 (MDN).
Foundation
📝 Syntax
JavaScript
assignedSlot
Value
An HTMLSlotElement instance, or null if the element is not assigned to a slot, or if the associated shadow root was attached with mode: "closed".
Item
Detail
Type
HTMLSlotElement | null
Access
Read-only
Assign via
slot="name" on light-DOM children
Needs
Open shadow root to observe the slot from outside
⚠️
Closed shadow roots hide the slot
Even if content is visually slotted, assignedSlot returns null when the host’s shadow root uses mode: "closed". Prefer mode: "open" while learning and debugging.
Pattern
📋 MDN Custom Element Example Shape
MDN’s simple-template pattern defines a custom element with a named slot my-text. Light-DOM content uses slot="my-text", then assignedSlot points at that <slot>:
JavaScript
<my-paragraph>
<span slot="my-text">Let's have some different text!</span>
</my-paragraph>
Element.assignedSlot is Baseline Widely available (MDN: across browsers since January 2020). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Element.assignedSlot
Read-only — returns HTMLSlotElement or null for Shadow DOM slot assignment.
BaselineWidely available
Google ChromeSupported (Shadow DOM)
Yes
Microsoft EdgeSupported (Shadow DOM)
Yes
Mozilla FirefoxSupported (Shadow DOM)
Yes
Apple SafariSupported (Shadow DOM)
Yes
OperaFollow Chromium support
Yes
Internet ExplorerNo Shadow DOM / assignedSlot
No
assignedSlotBaseline
Bottom line: Use assignedSlot to discover whicha light-DOM child is assigned to. Prefer open shadow roots for inspection. Always null-check the result.
Wrap Up
Conclusion
assignedSlot lets a slotted element report which <slot> it fills. Use open shadow roots while learning, null-check every read, and pair it with slot names and slotchange when building custom elements.