Inject stylus in Shadow DOM

inject stylus to shadowRoot

Autor
hdyzen
Dnevne instalacije
0
Ukupnih instalacija
1
Ocjene
0 0 0
Verzija
1.2
Stvoreno
29.06.2025.
Ažurirano
21.09.2025.
Size
1,51 KB
Licenza
GPL-3.0-only
Primjenjuje se
Sve stranice

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