The <slot> element is used for mark a content insertion point in a web component. You will run into it while reading other people’s HTML, and it is useful to know what job it does before copying the code.
What does <slot> mean?
Mark a content insertion point in a web component. The tag gives the browser a specific kind of content to work with. It is more helpful to choose a tag for its meaning than because of its default look.
Slots are meaningful inside a shadow root; JavaScript or declarative shadow DOM must provide that context.
A working HTML example
Here is a small example you can place in an HTML page and inspect in your browser:
<template id="card-template">
<article>
<h2><slot name="heading">Untitled</slot></h2>
<slot>Card details go here.</slot>
</article>
</template>
Reading the example
Find the <slot> part first. Notice which elements are around it and how its content or attributes are connected to those other elements.
In this example, <slot> appears alongside template or a shadow-root host. That context is often just as important as the element itself.
The browser builds its document from these relationships. Any CSS changes appearance, while interactive JavaScript behavior must be provided separately when the example includes it.
When should you use it?
Use <slot> when you want to mark a content insertion point in a web component. A sensible example of this on a real website is the markup shown above; it gives the browser and accessibility tools a clearer job to work with.
Common companions are template or a shadow-root host. Check the nesting requirements before moving the element into a different location.
Try it yourself
Make a small component with a heading slot and check what happens when no content is supplied.
Compatibility note: Customizable select features and component features have specific browser or shadow-DOM requirements. Use a working native fallback and test your target browsers.
Common Beginner Mistakes
- Slot alone in a normal page does not project content between components.
- Picking
<slot>only because it looks a certain way instead of checking what it means. - Forgetting to inspect the surrounding markup when an element does not behave as expected.
Key Takeaways
<slot>helps mark a content insertion point in a web component.- Slots are meaningful inside a shadow root; JavaScript or declarative shadow DOM must provide that context.
- Start with meaningful markup, then add styling or scripting only when the page needs it.