Limited supportLimited browser support. Check compatibility before use.

Overview

The :host-context() CSS pseudo-class selects the containing element of the shadow tree in which it is used if that element or an ancestor matches the provided selector.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
:host-context
Deprecated
54
79
54
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

CSS
:host-context(.dark-theme) {
  background: #333;
  color: #fff;
}
:host-context([dir='rtl']) {
  direction: rtl;
}

Live demo

Dark theme

CSS darktheme demo.

PreviewFullscreen

lighttheme

CSS lighttheme demo.

PreviewFullscreen

Rtlsupport

CSS RTLsupport demo.

PreviewFullscreen

Use cases

  • Using :host-context()

    The :host-context() CSS pseudo-class selects the containing element of the shadow tree in which it is used if that element or an ancestor matches the provided selector.

Cautions

  • Limited browser support. Check compatibility before use.

Accessibility

  • Make sure visual changes are conveyed appropriately to assistive technology.

Powered by web-features