How to use slots in Vue

Vue slots provide flexible component composition by allowing parent components to pass content into specific areas of child components. As the creator of CoreUI, a widely used open-source UI library, I’ve implemented slots in thousands of Vue components to create reusable and customizable interfaces. From my expertise, the most effective approach is using named slots for multiple content areas and default slots for simple content injection. This method enables flexible component design with clear content distribution patterns.

Use <slot> in child components and <template #slotName> in parent components for content distribution.

<!-- Child Component: Card.vue -->
<template>
  <div class="card">
    <header>
      <slot name="header"></slot>
    </header>
    <main>
      <slot></slot>
    </main>
    <footer>
      <slot name="footer"></slot>
    </footer>
  </div>
</template>

<!-- Parent Component -->
<template>
  <Card>
    <template #header>
      <h2>Card Title</h2>
    </template>

    <p>This is the main content</p>

    <template #footer>
      <button>Action</button>
    </template>
  </Card>
</template>

Slots act as placeholders in child components that can be filled with content from parent components. Use named slots with name attribute for multiple content areas and default unnamed slots for simple content injection.

Best Practice Note:

This is the same slot approach we use in CoreUI Vue components for flexible content composition. Provide fallback content in slots and use descriptive names for better component APIs and developer experience.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
Passing props to child components in React function components
Passing props to child components in React function components

How to migrate CoreUI React Templates to Vite
How to migrate CoreUI React Templates to Vite

How to disable a button in JavaScript
How to disable a button in JavaScript

How to remove a property from an object in Javascript
How to remove a property from an object in Javascript

Answers by CoreUI Core Team