DEV Community

Discussion on: How to Create a Web Component in Svelte

Collapse
 
bemisawa profile image
bemisawa

How do Svelte's slots work once items are compiled to web components? Is it possible to pass HTML in when using them on the page?

Collapse
 
silvio profile image
sil-vio

Hi bemisawa! yes it's possible to pass html to web components

For example if your web components is:

<div>
  <slot />
  <span>
    <slot name="secondslot"></slot>
  </span>
</div>
Enter fullscreen mode Exit fullscreen mode

you can use this way :

<my-component>
 default slot.
 <small slot="secondslot">second slot</small>
</my-componentn>
Enter fullscreen mode Exit fullscreen mode