Skip to content
Related Articles
Open in App
Not now

Related Articles

HTML <slot> Tag

Improve Article
Save Article
  • Last Updated : 28 Jul, 2022
Improve Article
Save Article

The slot is the element part of the web component technology which is a placeholder inside a component that you simply can fill together with your own markup, which allows you to make separate DOM trees and represent them together.




  • name: It describes the name of the slot.

Approach: The following elements are used in the example code given below.

  • Template: The template element is employed to declare fragments of HTML that will be inserted within the document by script. Contents aren’t rendered until they are added to the document in a script. This is often the part that contains the <slot> elements.
  • Content: This part contains the content that’s inserted where the <slot> elements are within the template. So during this case, the span elements will find yourself where the elements are available. Each span element refers to a selected <slot> element via its slot attribute. Any CSS that you simply include within the template element is merely applied to the DOM tree. It won’t affect the remainder of the page.
  • Script:  The primary list is inserted <slot> with the element but the second list isn’t. The main styles are declared inside the template element, which suggests that they are only applied to HTML elements that are within that shadow DOM tree. If the styles are outside of the template element, those styles are only applied to the second list, and therefore the first list goes unstyled.



<!DOCTYPE html>
<html lang="en">
        h1 {
            font-size: 2.2em;
            font-family: Arial, Helvetica, sans-serif;
            color: coral;
        dl {
            border-left: 5px solid yellowgreen;
            padding-left: 1em;
        dt {
            font-weight: bold;
            font-size: 2em;
        dd {
            color: darkslategray;
            font-size: 1.6em;
            <slot name="heading"></slot>
                <slot name="parent-1"></slot>
                <slot name="child-1"></slot>
                <slot name="parent-2"></slot>
                <slot name="child-2"></slot>
        <span slot="heading">GeeksforGeeks</span>
        <span slot="parent-1">GFG</span>
        <span slot="child-1">
            A computer science portal for geeks
        <span slot="parent-2">Slot tag</span>
        <span slot="child-2">
            Create separate DOM trees and present them together.
        let dlTemplate = document.querySelector('template').content;
        let sections = document.querySelectorAll('section');
        sections.forEach(function (section) {
            section.attachShadow({ mode: 'open' }).appendChild(


Supported Browsers:

  • Chrome 53 and above
  • Edge 79 and above
  • Firefox 63 and above
  • Opera 40 and above
  • Safari 10 and above
  • Internet Explorer not supported

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!