shadow DOM styles
Web Components โฉ Shadow DOM โฉ
MDN โฉ
CSS โฉ
Google โฉ
Web Component โฉ Component-defined styles
:host, :host(), :host-context(), ::slotted()
:host, :host(), :host-context() only works in the context of a shadow root, you can't use it outside of shadow DOM.
/* โญ๏ธ select host element (from inside shadow DOM) */
:host {
/* โญ๏ธ by default, custom elements are `display: inline` */
display: block;
/* CSS containment */
contain: content;
}
:host {
opacity: 0.4;
will-change: opacity;
transition: opacity 300ms ease-in-out;
}
/*
โญ๏ธ :host(<selector>) โญ๏ธ
-----------------
target the host if it matches a <selector>.
*/
:host(:hover) {
opacity: 1;
}
:host([disabled]) { /* style when host has disabled attribute. */
background: grey;
pointer-events: none;
opacity: 0.4;
}
:host(.blue) {
color: blue; /* color host when it has class="blue" */
}
:host(.pink) > #tabs {
color: pink; /* color internal #tabs node when host has class="pink". */
}
Topics
Examples
:host - <custom-dialog>, <user-card>, <element-details>
:host() - <custom-dialog>, <element-details>
::slotted() - <user-card>, <element-details> ๐ slotted content
Last updated
Was this helpful?