:host-context()
Limited availability78% of usersDeprecated
A pseudo-class used in Web Components to style the custom element based on its position in the outside page (e.g., styling a component differently if it's placed inside a 'dark-mode' container).
What's modern
From web-features, MDN's browser data and our snippets, checked dailyComingNot in Firefox or Safari yet, so not every major browser supports it.
See how modern your own CSS is.Check your CSS →
Quick example
:host-context(.dark-theme) {
/* Styles the component for dark theme if its parent has the class */
background-color: #333;
color: white;
}:host-context() browser support
BaselineLimited availabilityThis feature is not Baseline because it does not work in some of the most widely-used browsers.Not ready for production without a fallback.
Usage78%of people can use this22% use a browser without it.
Browsers
54+
79+Mobile
54+Android