Inject stylus in Shadow DOM

inject stylus to shadowRoot

Tác giả
hdyzen
Cài đặt hàng ngày
0
Số lần cài đặt
5
Đánh giá
1 0 0
Phiên bản
1.2
Đã tạo
29-06-2025
Đã cập nhật
21-09-2025
Kích thước
2 KB
Giấy phép
GPL-3.0-only
Áp dụng cho
Tất cả trang web

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