A simple custom element

Your own tag with its own behavior.

HTML · A simple custom elementAdvanced
<rating-stars value="3" max="5"></rating-stars>

<script>
  class RatingStars extends HTMLElement {
    connectedCallback() {
      const max = Number(this.getAttribute('max') || 5);
      const value = Number(this.getAttribute('value') || 0);
      this.attachShadow({ mode: 'open' }).innerHTML =
        '<style>span{color:#f59e0b}</style>' +
        '<span role="img" aria-label="' + value + ' of ' + max + '">' +
        '★'.repeat(value) + '☆'.repeat(max - value) + '</span>';
    }
  }
  customElements.define('rating-stars', RatingStars);
</script>
custom elementweb componentshadow domclass