The :host()
CSS pseudo-class function selects the shadow host of the shadow DOM containing the CSS it is used inside (so you can select a custom element from inside its shadow DOM) — but only if the selector given as the function's parameter matches the shadow host.
The most obvious use of this is to put a class name only on certain custom element instances, and then include the relevant class selector as the function argument. You can't use this with a descendant selector expression to select only instances of the custom element that are inside a particular ancestor. That's the job of :host-context()
.
Note: This has no effect when used outside a shadow DOM.
/* Selects a shadow root host, only if it is matched by the selector argument */ :host(.special-custom-element) { font-weight: bold; }