` is treated as an anonymous inline element, so the content
including legends and the `` in the third `` are displayed as they would be if they were in a `` instead. Let's define our element to convert this unrecognized element into a custom element. Custom elements JavaScript is required to define custom elements. When defined, the contents of the `` element will be replaced by a
shadow root containing all the contents of the template we associate with it. The `` elements from the template are replaced
with the contents of the element within the `` whose `slot` attribute value matches the ``'s name value, if
there is one. If not, the contents of the template's slots are displayed. Content within a custom element that isn't associated with a slotâthe `Is this text visible?
` in our third ``âis not included in
the shadow root and therefore not displayed. We [define the custom element](https://developer.mozilla.org/docs/Web/Web_Components/Using_custom_elements) named `star-rating`
by extending the `HTMLElement`: `customElements.define('star-rating', class extends HTMLElement { constructor() { super(); // Always call super first in constructor const starRating = document.getElementById('star-rating-template').content; const shadowRoot = this.attachShadow({ mode: 'open' }); shadowRoot.appendChild(starRating.cloneNode(true)); } });` Now that the element is defined, every time the browser encounters a `` element, it will be rendered as defined
by the element with the `#star-rating-template`, which is our template. The browser will attach a shadow DOM tree to the node, appending
a [clone](https://developer.mozilla.org/docs/Web/API/Node/cloneNode) of the template contents to that shadow DOM.
Note that the elements upon which you can [`attachShadow()` are limited](https://developer.mozilla.org/docs/Web/API/Element/attachShadow#elements_you_can_attach_a_shadow_to). `const shadowRoot = this.attachShadow({mode: 'open'}); shadowRoot.appendChild(starRating.cloneNode(true));` If you take a look at the developer tools, you'll note the `