Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE HTML> <html> <head> <title>Title of the Document</title> </head> <body> <style> user-card { --user-card-field-color: blue; } </style> <template id="tmpId"> <style> .field { color: var(--user-card-field-color, black); } </style> <div class="field"> Name: <slot name="username"></slot> </div> <div class="field"> Id: <slot name="id"></slot> </div> </template> <script> customElements.define('user-card', class extends HTMLElement { connectedCallback() { this.attachShadow({mode: 'open'}); this.shadowRoot.append(document.getElementById('tmpId').content.cloneNode(true)); } }); </script> <user-card> <span slot="username">Jack Brown</span> <span slot="id">112</span> </user-card> </body> </html>