๐Ÿ”ธ<template>

web โŸฉ component โŸฉ <template>

<template> tags (and their children)๏ผš

Use a <template> element to clone DOM, instead of setting shadowRoot.innerHTML. ๐Ÿ‘‰ Custom Elements โŸฉ Element-defined Content

HTML templates examples

๐Ÿ’พ replit.com

  • can put <style> and <script> into <template> as well.

<!-- styles and scripts in template -->
<template>

  <style>
    p { font-weight: bold; }
  </style>
  
  <script>
    alert("Hello");
  </script>
  
</template>
<!-- web component -->
<my-component>
  a "none" error message
</my-component>

<my-component kind="warning">
  this is a warning
</my-component>

<my-component kind="error">
  this is an error message
</my-component>

Last updated