<styled-element>test</styled-element>
class StyledElement extends HTMLElement {
constructor() {
super();
const shadow = this.attachShadow({ mode: "open" });
const style = document.createElement("style");
style.appendChild(document.createTextNode(`* { color: red; }`));
shadow.appendChild(style);
const div = document.createElement("div");
shadow.appendChild(div);
this.childNodes.forEach((childNode) => div.appendChild(childNode));
}
}
customElements.define("styled-element", StyledElement);
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.