<example-element>
<button>Light DOM Button</button>
</example-element>
button {
background: pink;
}
// ???
example-element button {
background: pink;
}
View Compiled
const template = document.createElement("template");
template.innerHTML = `
<slot></slot>
<button>Shadow DOM Button</button>
`;
class ExampleElement extends HTMLElement {
constructor() {
super();
this._shadowRoot = this.attachShadow({ mode: "open" });
this._shadowRoot.appendChild(template.content.cloneNode(true));
}
}
customElements.define("example-element", ExampleElement);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.