HTML slot Attribute

Beginner
6 min read
Updated: Nov 2026
3 examples
Live preview

Definition and Usage

The slot global attribute assigns a light-DOM child to a named <slot> inside a parent’s shadow tree. Put slot="name" on the content you distribute; put matching <slot name="name"> in the component’s shadow root.

This is the light-DOM side of Web Components composition. Without a matching named slot, content falls through to the default (unnamed) <slot> if one exists.

Attribute vs element.

The slot attribute lives on light-DOM children. The <slot> element lives in the shadow tree and displays that content.

Only with shadow DOM.

On a normal host without a shadow root, slot has no composition effect — it is just an unused attribute.

HTML Syntax

syntax.html
<element slot ="slot-name">

The value is a string that must match a <slot name="..."> in the host’s shadow tree. Omit the attribute to use the default slot.

Attribute Values

ValueDescriptionTry it
slot-nameAssigns this node to <slot name="slot-name">Try it
absent / emptyGoes to the default unnamed <slot> (if present)Try it
unknown nameNot shown in any named slot; may fall through to defaultTry it

Live Preview

A custom element with named slots for title and body. Toggle which content is slotted.

Uses a real shadow root with <slot name="title"> and a default slot.

Result
Hello slot

Default body content

title is slotted

HTML Examples

Example 1 — Named Slot Assignment

Light-DOM content with slot="title" fills the named shadow slot.

HTML
<user-card>
  <span slot="title">Ada Lovelace</span>
  <p>Mathematician</p>
</user-card>

<!-- Inside shadow root: -->
<!-- <h2><slot name="title"></slot></h2> -->
<!-- <slot></slot> -->
Try It Yourself

How It Works

  1. Declare <slot name="title"> in the shadow tree.
  2. Put slot="title" on the light-DOM child.
  3. The browser projects that child into the matching slot.
  4. Unnamed children go to the default <slot>.

Example 2 — Default (Unnamed) Slot

Omit slot so content fills the unnamed shadow slot.

HTML
<info-box>
  <p>This paragraph has no slot attribute.</p>
</info-box>
Try It Yourself

How It Works

  1. No attribute means “default slot”.
  2. Shadow must include an unnamed <slot>.
  3. Fallback text inside <slot> shows when nothing is assigned.
  4. Named-only hosts hide unassigned default content.

Example 3 — Header, Body, Footer Slots

Compose a card with three named regions.

HTML
<app-card>
  <h3 slot="header">Status</h3>
  <p slot="body">All systems go.</p>
  <button slot="footer" type="button">OK</button>
</app-card>
Try It Yourself

How It Works

  1. One name per region in the shadow template.
  2. Match names exactly — they are case-sensitive strings.
  3. Order in light DOM does not have to match visual order.
  4. Style the host/slots; slotted nodes keep their own styles.

Edge Cases & Pitfalls

Most confusion comes from mixing up the attribute and the element.

name

Names must match exactly

slot="Title" does not fill <slot name="title"> — matching is case-sensitive.

scope

Only the host’s shadow tree

slot assignment is relative to the immediate shadow host, not ancestors.

fallback

Slot fallback content

Text inside <slot> appears only when nothing is assigned to that slot.

vs-tag

Attribute ≠ element

Document the <slot> element separately at /html/tags/slot.

Browser Support

slot is an HTML attribute for browsers. It is not a Node.js, Deno, or Bun API.

✓ Widely available

slot

Shadow DOM slot assignment works in modern Chromium, Firefox, and Safari.

95% Global support (approx.)
Google Chrome 73+
Full support
Mozilla Firefox 72+
Full support
Apple Safari 13.1+
Full support
Microsoft Edge 79+
Full support
Opera 60+
Full support
Samsung Internet 11+
Full support
Internet Explorer No support
Not supported
slot Modern browsers

Bottom line: Safe for Web Components on modern sites. No IE support.

Key Takeaways

  • Role: map light-DOM content into a named shadow <slot>.
  • Value: a slot name matching <slot name> in the shadow tree.
  • Default: no attribute (or unknown name) targets the unnamed slot.
  • Related: see the <slot> element for the shadow side.

One line: slot tells a shadow host which named <slot> should receive this light-DOM child.

Frequently Asked Questions

It names which shadow <slot> a light-DOM child should fill when the host uses a shadow tree. The value must match a <slot name="..."> inside the shadow root.
No. The attribute goes on light-DOM children. The <slot> element lives in the shadow tree and receives that content.
Children without slot (or with an empty/unknown name) go into the default unnamed <slot> if the shadow tree provides one.
The attribute is global, but it only affects composition when the parent element has a shadow root with matching <slot> elements.
Yes. Each host’s light-DOM children are assigned relative to that host’s shadow tree — not the outer page’s slots.
Shadow DOM and slot assignment are widely available in modern browsers. Older IE has no support.

Next: spellcheck

Enable or disable browser spelling checks on editable text.

spellcheck tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful