Slots, Slots, Slots, Everybody!

This ad is not shown to multipass and full ticket holders
React Summit
React Summit 2026
June 11 - 15, 2026
Amsterdam & Online
The biggest React conference worldwide
Learn More
In partnership with Focus Reactive
Upcoming event
React Summit 2026
React Summit 2026
June 11 - 15, 2026. Amsterdam & Online
Learn more
Bookmark
Rate this content

Let's use slots to fill Lil Jon's club with people! Starting with web components, we'll walk through how to use slots to make highly extensible wrappers for dynamic content. Then we'll talk about how Vue and Angular leverage this HTML feature and how React children are different.

This talk has been presented at React Summit US 2025, check out the latest edition of this React Conference.

FAQ

Slots are placeholders in components that allow you to pass dynamic content into them. In Vue and Angular, they extend the web component spec to provide this functionality, allowing for more flexible and reusable components.

No, React does not use slots. Instead, React uses the children prop to pass content into components, allowing for similar flexibility without the slot syntax.

The shadow DOM is used in custom elements to encapsulate the DOM structure and styles, preventing them from being affected by the rest of the document's styles and scripts.

In Vue, named slots are implemented using the template tag with the v-slot directive. You specify the slot name using the v-slot:slotName syntax, and pass content to these slots using the corresponding slot attribute.

Content projection in Angular is similar to slots in Vue and web components. It uses the ng-content tag to define where dynamic content should be inserted within a component's template.

CSS styles defined outside the shadow DOM do not affect its content. Styles must be defined within the shadow DOM to apply to its elements, ensuring encapsulation.

Default slots are unnamed and used for unspecified content, while named slots have a specific name and are used for content passed with a matching slot attribute.

Conditional rendering in Vue can be achieved using the v-if directive on elements that contain slots, allowing you to render content based on certain conditions.

Yes, Angular allows the use of CSS selectors with the ng-project-as attribute to match and project content into specific slots, based on element attributes or classes.

In web components, slots work by using a template tag with a slot tag inside it. You can pass content to these slots, which will replace the default content defined in the template when the component is rendered.

Abbey Perini
Abbey Perini
20 min
21 Nov, 2025

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Abbe explains how slots enhance dynamic content in components and demonstrates creating a custom element with the shadow DOM. The content covers utilizing slot attributes for named slots and slot buttons for navigation within components. It explores styling effects on components, default and named slots usage in Vue components, access and management of slot props using scoped default slots in Vue, and dynamic list creation with JavaScript destructuring in Vue components. Additionally, it discusses name slots in Angular for content projection, CSS selector matching, slot selectors, conditional content projection with ng-template, and view encapsulation modes like Shadow DOM API.
Available in Español: ¡Slots, Slots, Slots, Todos!

1. Understanding Slots in Web Development

Short description:

Abbe explains how slots enhance dynamic content in components. She introduces web components, detailing the use of template and slot tags in HTML. Abbe demonstrates creating a custom element with the shadow DOM for styling and encapsulation.

You ready to talk about slots, slots, slots, everybody? I'm Abbe, a former React developer, and when I started learning Vue, I was like, what the heck are slots? Slots turn components into wrappers that enhance your dynamic content. So instead of having to decide exactly what your component is going to do when you write it and isn't allowed to do anything else, you can use a slot to create a little placeholder and pass whatever content to that however you want.

We're going to start with the web component spec and then how React, Vue, and Angular leveraged that spec to use slots in the frameworks. All of this information will be available to you after the talk is over, so you don't have to remember any of the implementation. Just think about how to use slots.

We're going to start with web components. They're part of the HTML spec. Everything I'm about to show you is available in your browser with JavaScript and HTML right now. First, we need a template tag and a slot tag. In my HTML file, I have a template tag with an ID. It's got some styling in it, and then inside a div container, a handful of slots. This first slot is a default slot. It doesn't have a name. The second slot is using the name attribute with the value title to name the slot title. Inside it is default content. This is what we'll show if we don't pass anything to the slot. This slot is wrapped in an H2 or heading element. Anything I pass to that slot will be wrapped in a heading element. Inside this next slot named content, I have a paragraph tag. Whatever I pass to that slot will overwrite the paragraph tag. Next, we need a custom element with the shadow DOM. I'm using the custom elements API to define a component called shots component. Then I'm passing the class name shots to it. This is extending HTML element, so we get all the goodies you get with a basic HTML element. Then I'm inside the constructor. I'm grabbing the template tag by the ID, creating a shadow DOM, which is just an encapsulated little DOM inside your regular DOM. Inside that shadow DOM, I'm appending a copy of all the content inside that template tag, and I'm adding a class to make it easier to style. I'm going to call the component. I'm going to use this name that I passed to the definition method. At the top of my HTML file, I have shots component.

2. Utilizing Slot Attributes and Navigation Buttons

Short description:

Content includes passing default content using slots, utilizing slot attributes for named slots, and demonstrating the use of slot buttons for navigation within components.

All the content I want to pass to it is currently commented out. I'm not passing anything into it, and we should see the default content. We should see Sad Little John because there are no shots, and we do. As you can see, the template tag is mounted, but that's not what's being displayed on the page. That's our shots component call. Inside the template tag is a document fragment, and inside that document fragment is all of the content that was in that template tag in our HTML file. Inside the component is a shadow root with all of the content that was inside the template tag.

Next, let's use a slot attribute to pass some content to our slots. This first element has a slot attribute with the value title, so this content should go in the slot named title. Same for the rest of the named slots, but this last one doesn't have the slot attribute on it. All of its content will go into the default slot. Even though I'm passing it at the bottom, the default slot is at the top, so I expect to see shots, shots, shots above Happy Little John because we have shots now, and we do. Inside my component now that I'm passing some content, there are slot buttons.

Pressing this button will take me to the slot that that content is being put in, and if I expand the slot, then I get a reveal button that takes me back to the slot that it's being passed to. So, we talked about the slot and the reveal button. We saw the template tag is mounted. It has a document fragment in it. The template tag itself is not displayed. There's a shadow root, and inside it, the slot tags are mounted, and now we need to talk about how the shadow DOM affects CSS.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

The Good, The Bad, and The Web Components
JSNation 2023JSNation 2023
29 min
The Good, The Bad, and The Web Components
Top Content
Web Components are a piece of reusable UI enabled by web standards and built into the web platform. They offer the potential for faster component initialization and less library overhead. Web Components can be created from scratch and utilized with existing component libraries. Shadow DOM and Declarative Shadow DOM provide benefits such as scoped CSS and server-rendered components. The tradeoff between not repeating oneself and achieving full server-side rendering support is discussed. User experience is deemed more important than developer experience.
It's Time to De-Fragment the Web
React Day Berlin 2022React Day Berlin 2022
34 min
It's Time to De-Fragment the Web
Top Content
Today's Talk introduces Mitosis, an open source project that solves the problem of building framework agnostic components. It supports JSX and Svelte syntax and outputs human-readable code for various web frameworks. Mitosis is already being used by enterprise customers and can be easily integrated with React, Svelte, and other frameworks. It saves time, allows for easy handling of framework version migrations, and enables efficient unit and integration testing.
Authoring HTML in a JavaScript World
React Summit US 2023React Summit US 2023
21 min
Authoring HTML in a JavaScript World
Watch video: Authoring HTML in a JavaScript World
This Talk by Tony Alicia focuses on authoring HTML in a JavaScript world. The speaker challenges developers to change their approach to building React components by starting with HTML first. By authoring HTML in a semantic way, readability and maintainability can be improved. Well-authored HTML provides better understanding of content and improves accessibility. It also has performance benefits by reducing DOM size. Investing time in HTML can save time and make applications more future-proof.
Web Components, Lit and Santa 🎅
JSNation Live 2021JSNation Live 2021
28 min
Web Components, Lit and Santa 🎅
Web Components and the Lit library are introduced, highlighting their ability to create custom elements and replicate built-in components with different functionality. The use of semantic HTML and the benefits of web components in development are emphasized. The features of Lit, such as data binding and rendering, are discussed. The Santa Tracker is showcased as an example of web components being used in educational games. The compatibility of web components with other frameworks and their versatility in creating small widgets or large applications are highlighted.
How the Shadow DOM has Got You Covered?
React Day Berlin 2023React Day Berlin 2023
18 min
How the Shadow DOM has Got You Covered?
Watch video: How the Shadow DOM has Got You Covered?
The Shadow DOM allows for encapsulation and composability, enabling elements to have their own features without affecting the rest of the webpage. Custom elements in the Shadow DOM have their own behavior through encapsulation and scoped styles. Composability is key in software development, allowing for dynamic data passing. The Shadow DOM provides a way to modify the appearance of elements within it, but some properties are marked as important and cannot be changed. Building a Chrome extension using the Shadow DOM allows for composable and encapsulated experiences.
Web Components are awesome!
JSNation 2022JSNation 2022
10 min
Web Components are awesome!
Web components allow you to create your own HTML elements that can do anything you want, and they are supported by all modern browsers. Many companies, including YouTube and GitHub, use web components to enhance their websites. There are extensive tooling and libraries available for web component development. The Model Viewer Web Component enables the display of 3D models in Virtual and Augmented Reality without needing to know underlying technologies. Web components can be used with various frameworks and libraries, and there are resources available to help with compatibility.

Workshops on related topic

Web Components in Action
JSNation Live 2021JSNation Live 2021
184 min
Web Components in Action
Workshop
Joren Broekema
Alex Korzhikov
2 authors
The workshop extends JavaScript programming language knowledge, overviews general software design patterns. It is focused on Web Components standards and technologies built on top of them, like Lit-HTML and Lit-Element. We also practice writing Web Components both with native JavaScript and using Lit-Element. In the end we overview key tooling to develop an application - open-wc.