Vue Slots

Pass content into a component.

✍️ 3 exercises + code challenge in this lesson

A <slot> marks where content passed between the component's tags appears.

  • Default slot: <slot></slot>
  • Named slots: <slot name="footer">, filled with <template #footer>
  • Fallback content goes inside the slot tag.

Key Takeaways: Vue Slots

Mastering Vue Slots helps you write clean and reliable Vue.js code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

Vue Slots Code Example

Vue.js
<script src="https://unpkg.com/vue@3.5.12/dist/vue.global.prod.js"></script>

<div id="app">
  <panel>
    <p>This content goes into the default slot.</p>
    <template #footer>Footer text</template>
  </panel>
</div>

<script>
  const app = Vue.createApp({});
  app.component("panel", {
    template: `<section style="border:2px solid #42b883;border-radius:8px;padding:10px">
                 <slot>Nothing here</slot>
                 <footer style="color:#64748b"><slot name="footer"></slot></footer>
               </section>`
  });
  app.mount("#app");
</script>
Free sign-in required · Google login available

Vue Slots Practice Exercises

Check what you learned in “Vue Slots”.

/ 3 solved
Fill in the blank

Mark where passed-in content appears.

template: `<div class="box"><></></div>`
✓ Correct! Not quite. Try again.
Multiple choice

How do you fill a named slot called "footer"?

✓ Correct! Not quite. Try again.
Code challenge

The card component ignores its content. Add a <slot> so "Inside card" appears in the .card div.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services