Forwarding content with a slot element

Introduction

vue slot

One of the ways to forward the content from the parent component is to insert it between the custom tag that represents the instance of the component. This mechanism is used when we have similar components that differ only in content, because this way we avoid creating two separate components. The
Child component accepts the passed content, and the “slot” element defines the place in the component where the passed content should be inserted.

Example


Unnamed slot

This is the simplest way to pass some content from the root Vue instance (or parent component) to a child component. That content is passed between the HTML tags that represent the instance of the child component. It has already been mentioned that the contents will be used when rendering the instance at the place where the <slot></slot> element is located.

Root instance:

Component

The component accepts the passed content and displays it in place of the slot tag

When the component is rendered, the passed content will come into the slot tag.

NOTE:
Inline content styling must be styled from a child component.

Dynamic content can also be passed to the component:

Example

And such a component accepts the passed content exactly the same and displays it in place of the slot tag. Therefore, dynamic content will be rendered in place of the slot HTML tag, which in this case is “<h3>Something bad happened.</h3>”

Named slot

Vue 3 note (2026): In Vue 3, prefer v-slot:name / #name. The old slot="name" attribute syntax is removed in Vue 3.

In case there are several slots, it is necessary to assign a name to each slot to distinguish them from each other:

Root instance

Component

The component accepts the passed content and displays it in place of the corresponding slot tag:

Default slot

It should be emphasized that if one of the slots does not have a defined name, it will behave as the so-called. default slot that marks the place where all forwarded content that is not specifically marked will be displayed.

Root instance

Component

The named slot “<slot name="title"></slot>” accepts its content in a tag marked with v-slot:title / #title (Vue 2 used slot=”title”), while the unnamed slot accepts all untagged content passed: