liveBook · Manning

Named slot

As explained in Web Components in Action

A slot identified by a name so that matching child content can be assigned to a specific distribution point.

A named slot creates a labeled distribution point in a Shadow DOM template. Child content carrying the matching slot attribute appears at that point, while fallback text remains available when no value is supplied.

Build the relationship in two steps:

  • Use an unnamed slot when simple default content is enough; omitting names removes the ability to target multiple distribution points. section 7.5

Business card content

A component can define <slot name="firstname">First</slot>, then receive <span slot="firstname">Ben</span>. The entire span is distributed, so the assigned content could instead be a button or another slot. section 7.5

How Web Components in Action covers it

How deep it goes
Explains declarations, matching attributes, fallback content, and unnamed alternatives, but stops short of slot API internals.
Examples
Demonstrates a business card with named personal details and a generic component using an unnamed slot.
What it assumes
Assumes basic HTML and custom-element usage while introducing Shadow DOM content distribution through examples.
What you can do after
Apply it via Web Components by declaring named placeholders and assigning matching child content.
How it connects
Connects named slots with Shadow DOM, custom elements, Web Components, and HTML content distribution.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Components in Action. The section links point to the parts of the book it draws on.