Hacker News new | past | comments | ask | show | jobs | submit login

I fairly recently used Shadow DOM for a project. We built a widget that was embedded in a web page, and that page could be arbitrarily styled. The outside page was typically a Wordpress theme, which in most cases did all kind of nasty things with CSS.

Even though there is CSS encapsulation, styles can still leak (cascade?) from the parent element into the Shadow DOM. You therefore need to put a style tag on the root that resets all styles.

Even then, there are some things like CSS transformations that will still affect elements within a Shadow DOM.

Another weirdness is that React modals are usually going to break unless you pass them a reference to the Shadow Root. Most popular libraries have been modified to take such a reference.




Yes but it doesn't leak CSS when you want it to, I've never figured how to setup a CSS only dark theme using a top-level classname like Tailwind does for instance


CSS custom properties are what you’re looking for here.

They cascade into the ShadowDOM without any issues.


If you want classnames:

- <my-component class="dark"

- :host(.dark) to style inside the component




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: