style[scoped] polyfill
npm install style-scopedThis is a polyfill for scoped CSS, also known as , a feature that is useful for building simple components (but which was removed from the HTML specification around 2016).
Check out a small demo.
Include the polyfill (via your favourite package manager as style-scoped) and then include a tag:
``html`
I'm red
I'm not
This can help you provide CSS encapsulation for your projects.
The library is about ~1.9k minified and gzipped.
The polyfill supports Firefox, Safari and Chromium-based browsers (and should support IE11 and above).
(It requires browsers with WeakMap and MutationObserver).
The code works by applying a custom attribute name, e.g. __scoped_123, to the parent element of the
Note that
:scope is supported by most modern browsers—but without