Inject Stylus into shadowRoots

hdyzen
2025-06-29T23:07:45Z

inject styles of stylus-addon in shadowRoot

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