Inject stylus in Shadow DOM

inject stylus to shadowRoot

Penulis
hdyzen
Pemasangan harian
0
Total pemasangan
1
Nilai
0 0 0
Versi
1.2
Dibuat
29 Juni 2025
Diperbarui
21 September 2025
Size
1,51 KB
Lisensi
GPL-3.0-only
Berlaku untuk
Semua situs

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