pseudo-class
:host() — CSS reference
Matches the host only if the argument compound selector matches it in the outer context. Its specificity includes the pseudo-class and the argument. It only works in the relevant shadow stylesheet.
Formal Syntax & Structure
css syntaxcss
:host(.featured) { color: teal; }Working Example
Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS reference lab</title><style>#b {color:#202020}</style><body><div id="a" class="featured"><span id="slot" class="label">Assigned text <b id="nested">nested</b></span></div><div id="b">Outside</div><script>const root=a.attachShadow({mode:"open"});root.innerHTML="<style>:host(.featured) {color:#006050}</style><slot></slot><p id=\"inside\" part=\"label\">Inside</p>";</script></body></html>