Inject Stylus into shadowRoots

inject styles of stylus-addon in shadowRoot

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Аўтар
hdyzen
Усталяванняў за дзень
0
Усяго ўсталяванняў
8
Рэйтынг
1 0 0
Версія
2.2
Створаны
29.06.2025
Абноўлены
18.10.2025
Памер
2.6 КБ
Ліцэнзія
GPL-3.0-only
Ужываецца на
Усе сайты

Inject Stylus in Shadow DOM

Userscript that automatically injects styles from Stylus (and other userstyle managers) into any shadowRoot.
This allows you to customize web components and encapsulated elements that normally would not inherit your styles.


  • Supports:
    • Stylus
    • Stylish
    • xStyle
    • User JavaScript and CSS
    • Amino Live Editor
    • Stylebot
    • Magic CSS
    • Custom CSS by Denis

Styling inside a shadowRoot

The key selector is :host.
It refers to the shadow host element of the shadowRoot, letting you apply styles only inside the shadow boundary.

/* Apply to all elements on the page */
* {
  border: 1px solid violet;
}

/* Apply only to elements inside the shadowRoot */
:host * {
  border: 1px solid mediumpurple;
}

/* Apply styles only if the host has a specific class */
:host(.dark-theme) {
  border: 1px solid blue;
}

Useful variations

  • :host() — conditionally apply styles when the host matches a selector.
  • :host-context() — apply styles based on the host’s external context (not supported in Firefox)

Installation

  1. Install a userscript manager such as Violentmonkey
  2. Install the script on GreasyFork
  3. Create or edit your styles with Stylus or another supported extension

License

GPL-3.0-only