What are slots in Vue?

BeginnerVue interview questionBy , updated 17 November 2026

Short answer

Slots let a parent pass template content into a child component. The child marks where that content goes with a <slot> element, and can put fallback content inside it for when nothing is passed. A component can have one default slot and any number of named slots, filled with v-slot:name or the #name shorthand. Scoped slots go further: the child passes data back to the parent's slot content, like a render prop in React.

The default slot

Props pass data to a child. Slots pass markup. A button or card component usually needs both.

<!-- FancyButton.vue -->
<template>
  <button class="fancy-btn">
    <slot>Submit</slot> <!-- "Submit" is the fallback content -->
  </button>
</template>
<FancyButton>Save changes</FancyButton>   <!-- renders "Save changes" -->
<FancyButton />                            <!-- renders "Submit" -->
<FancyButton><Icon name="save" /> Save</FancyButton>

Anything between the component's tags goes to the default slot, including other components. The slot content is compiled in the parent's scope: it can use the parent's data and methods, and it cannot see the child's state. The child decides where and whether the content appears, not what it is.

Named slots

When a component has several places for content, give each <slot> a name. A slot without a name is called default.

<!-- BaseCard.vue -->
<template>
  <article class="card">
    <header v-if="$slots.header"><slot name="header" /></header>
    <div class="body"><slot /></div>
    <footer v-if="$slots.footer"><slot name="footer" /></footer>
  </article>
</template>
<BaseCard>
  <template #header>
    <h2>Order #1042</h2>
  </template>

  <p>Three items, shipping tomorrow.</p> <!-- goes to the default slot -->

  <template v-slot:footer>
    <button @click="track">Track order</button>
  </template>
</BaseCard>

#header is shorthand for v-slot:header, and both must be on a <template> element (or on the component itself for the default slot only). Content not inside a named <template> goes to the default slot. You can also name a slot dynamically with #[slotName].

Checking whether a slot was passed: $slots

$slots in the template is an object of the slots the parent actually provided. The v-if="$slots.footer" above avoids rendering an empty <footer> with its padding and border. In <script setup>, useSlots() returns the same object. Each entry is a function, which matters when you write render functions: you call slots.default?.() to get the nodes.

Scoped slots: data flows back to the parent

Sometimes the child owns the data but the parent should decide how each piece looks. A list or table component is the classic case. The child binds attributes on <slot>, which become slot props for the parent.

<!-- DataList.vue -->
<script setup>
defineProps({ items: { type: Array, required: true } });
</script>

<template>
  <ul v-if="items.length">
    <li v-for="(item, index) in items" :key="item.id">
      <slot name="item" :item="item" :index="index">{{ item.label }}</slot>
    </li>
  </ul>
  <slot v-else name="empty"><p>No results.</p></slot>
</template>
<DataList :items="users">
  <template #item="{ item, index }">
    <strong>{{ index + 1 }}.</strong> {{ item.name }} ({{ item.email }})
  </template>
  <template #empty>
    <p>No users yet. <a href="/invite">Invite someone</a>.</p>
  </template>
</DataList>

DataList handles looping, keys and the empty state; the parent controls the markup for each row. You can destructure slot props, rename them and give defaults, just like function parameters. If a component only has a default scoped slot, put v-slot on the component itself: <DataList :items="users" v-slot="{ item }">. The name attribute is reserved and is not passed as a slot prop.

In TypeScript with <script setup lang="ts">, defineSlots() declares slot names and their props, so the parent gets type checking and editor hints for item.

Compared with React

Vue React equivalent
Default slot children
Named slots Props that hold JSX, such as header={<h2>...</h2>}
Scoped slot A render prop or function as child, such as renderItem={(item) => ...}
Fallback content children ?? "Submit"
$slots.footer check props.footer != null

The ideas map closely, but the syntax differs. React passes everything as props, and a render prop is just a function prop. Vue gives the pattern dedicated template syntax and compiles slot content into functions that the child calls. The React side is covered in the render props pattern, and Vue's other ways for parents and children to talk, props, emits and v-model, are in how props, emits and v-model work.

When to use slots

  • Layout and wrapper components: cards, modals, page shells, tabs.
  • Generic list, table and dropdown components where the consumer styles each item.
  • Components that should accept rich content such as icons or links, which a string prop cannot carry.

Use a prop when the value is plain data, such as a title string or a number. Use a slot when it is markup the parent should control.

Practise it

Compose card components three ways: slots, a compound Card API and a tweet card practises the same composition idea in React, and Build Switch, Case and Default components works with children as content. Build a web component with shadow DOM, slots and attribute and property sync shows native slots, which inspired Vue's, and Build a sortable and filterable data table is a natural fit for scoped slots for custom cells.

Common follow-up questions

Can the slot content access the child's data?

Only through slot props. Content is compiled in the parent's scope, so it sees the parent's state. To expose the child's data, bind it on <slot> and read it with #name="props".

Are Vue slots the same as Web Component slots?

They are inspired by the native <slot> element and the same default and named idea. Native slots display the host element's own child nodes at a point in its shadow root, without moving them, and have no scoped slots. Vue slots are part of its virtual DOM and can pass data back.

What happened to slot-scope and $scopedSlots?

They are Vue 2 APIs. Vue 2.6 introduced the unified v-slot syntax, and Vue 3 removed $scopedSlots: every slot is now a function in $slots.

Can a slot be rendered more than once?

Yes. A scoped slot inside a v-for is called once per item, as in DataList above. Each call gets its own slot props.

Mistakes to avoid

  • Expecting slot content to read the child's variables without slot props

  • Putting v-slot on a plain element instead of <template> or the component

  • Mixing v-slot on the component with named <template> slots; use an explicit <template #default> when you have both

  • Rendering wrapper markup for an empty optional slot instead of checking $slots

  • Using a slot for plain data that should be a prop

Practise it in code

Interviewers rarely stop at the definition. These questions open in an editor with tests.

  1. Compose card components three ways: slots, a compound Card API and a tweet cardMedium45 min
  2. Build Switch, Case and Default componentsMedium30 min
  3. Build a web component with shadow DOM, slots and attribute and property syncMedium40 min
  4. Build a sortable and filterable data tableMedium35 min