pseudo-class

:host-context() — CSS reference

From a shadow stylesheet, checks the host or an ancestor against the argument. This couples component appearance to surrounding markup. Prefer explicit theme inputs or inherited custom properties when possible; verify support before using this selector.

Formal Syntax & Structure

css syntaxcss
:host-context(.theme) { 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><section class="theme"><div id="a" class="featured"><span id="slot" class="label">Assigned text <b id="nested">nested</b></span></div><div id="b">Outside</div></section><script>const root=a.attachShadow({mode:"open"});root.innerHTML="<style>:host-context(.theme) {color:#006050}</style><slot></slot><p id=\"inside\" part=\"label\">Inside</p>";</script></body></html>
CSS Reference