Pass HTML Markup From Parent TO CHILD In Lightning Web Component

You might have passed data from Parent Lightning web Component to Child Lightning Web Component but have you ever came across any requirement to pass HTML markup from Parent to child in Lightning Web Component? If yes, how would LWC framework allows you to pass HTML markup from parent to child Lightning Web Component?

Here comes the <slot></slot> to save you from such situation. A slot (<slot></slot>) is a placeholder for markup that a parent component passes into a component’s body. Slots are part of the Web Component specification.

Two things you should keep in mind before you start :-

  • Add a slot to a child component’s HTML file so a parent component can pass markup into the component.
  • A child component can have zero or more slots.

Different Types of Slot

  1. Unnamed Slots – A slot without a name attribute.
  2. Named Slots – A named slot is a <slot> element with a name attribute.

Unnamed Slots

According to Salesforce Documentation, An unnamed slot is a placeholder for any markup that a parent component passes into the body of the child component. To understand more about it, lets create a Lightning Web Component with name componentWithUnnamedSlot.

Any Lightning Web Component will be created with three files. So when you do create componentWithUnnamedSlot, You got these files beneath it:-

  1. componentWithUnnamedSlot.html
  2. componentWithUnnamedSlot.js
  3. componentWithUnnamedSlot.js-meta.xml


The html file have two div elements. One of the div element has the header and another one contains the <slot></slot> element which is a unnamed slot.

    <div class="slds-text-heading_large">
        Learning Unnamed Slot 


We are going to leave the code as it is in it without making any change.

import { LightningElement } from 'lwc';

export default class ComponentWithUnnamedSlot extends LightningElement {}


We are not going to expose this component to any Record, Home or App page as we will be calling it inside parent component.

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="">

Its time to deploy the child component and create another component with name parentLightningWebComponent which will be the parent Lightning Web Component.


The html file of the parent component calls the child component c-component-with-unnamed-slot. As c-component-with-unnamed-slot has unnamed slot, It gives you the flexibility to pass the HTML markup from parent Lightning web Component.

        <div class="slds-card">
            <div class="slds-m-around_medium">
                <h1 class="slds-text-heading_small">HTML MARKUP</h1>
                <p class="slds-text-body_regular">The following examples show how you can pass markup to child Lightning Web Component from Parent Lightning Web Component</p>
                <h2>Basic Input Date</h2>
                <lightning-input type="date" name="input1" label="Enter a date" ></lightning-input>            


import { LightningElement } from 'lwc';

export default class ParentLightningWebComponent extends LightningElement {}


The parent Lightning Web Component has been exposed to Lightning Home Page.

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="">

Demo – Pass Markup to Slots

Let’s add the parent Lightning Web Component we have created to Lightning Home Page using Lightning App Builder. After adding it to page, Save the page and Activate it. You will see below:-


Keep Checking out our blog for understanding named Slots and other features related to Slots here:-


  1. A really simple and basic real time scenario is lightning modal. You might want to build a generic modal so that it can be reused by defining the content of the body.

Leave a Reply