A slot is a placeholder inside a component where you can insert custom content from the parent. It helps to make components flexible and reusable.
Click to reveal answer
intermediate
How do you define a named slot in Astro?
You define a named slot by adding a <slot name="slotName" /> tag inside your component. The parent can then pass content to that slot by using
content
.
Click to reveal answer
beginner
What happens if no content is passed to a slot in Astro?
If no content is passed to a slot, Astro renders the default content inside the <slot> tag, if any is provided. Otherwise, the slot remains empty.
Click to reveal answer
intermediate
Why use slots instead of props for content in Astro components?
Slots allow you to pass complex HTML or components as content, not just simple data. This makes your components more flexible and lets you control layout better.
Click to reveal answer
beginner
Show a simple example of using a default slot in Astro.
Inside your component: Default content here. When used: Custom content. The custom content replaces the slot content.
Click to reveal answer
What tag is used to create a slot in an Astro component?
A<placeholder>
B<slot>
C<insert>
D<content>
✗ Incorrect
The tag defines where the projected content will appear inside the component.
How do you pass content to a named slot called 'header' in Astro?
A. The slot named "footer" is not defined inside the component
B. Slots cannot be used with <div> elements
C. The default slot is missing a name attribute
D. The component must have only one slot
Solution
Step 1: Check slot names in component
The component defines slots named "header" and default (unnamed), but no "footer" slot.
Step 2: Check usage slot names
The usage tries to fill a "footer" slot which does not exist, so content won't render.
Final Answer:
The slot named "footer" is not defined inside the component -> Option A
Quick Check:
Undefined slot name = no content rendered [OK]
Hint: Slot names must match exactly between usage and component [OK]
Common Mistakes:
Thinking any slot name works without definition
Believing slot attribute restricts element types
Assuming default slot needs a name
5. You want to create a reusable Card component with slots for header, body, and footer. Which Astro component code correctly sets up these named slots?
hard
A.
B.
C.
D.
Solution
Step 1: Recall correct slot syntax
Named slots in Astro use self-closing tags like <slot name="name" /> to define placeholders.
Step 2: Evaluate options
<slot name="header" />
<slot name="body" />
<slot name="footer" /> uses correct self-closing syntax for all three slots. <slot-header />
<slot-body />
<slot-footer /> uses invalid custom tags. <slot name="header">
<slot name="body">
<slot name="footer"> nests slots incorrectly. <slot name="header"></slot>
<slot name="body"></slot>
<slot name="footer"></slot> uses non-self-closing tags which Astro does not support for slots.