This demo uses an Accordion web component (wc) to showcase CSS scoping in Web Components.
The Accordion wc uses generic css class selector names, .title
, .panel
, and .panel-content
that don't interfere
with same selectors on the page. Styles in wc are encapsulated.
The page is can only style Accordion wc if it exposes the styles to be stylable.
It demonstrates the behavior with the following use cases:
<slot>
The demo uses the two following CSS properties in the Accordion header to highlight the behavior:
.panel-content
. Their styles don't interfere. Accordion styles are encapsulated inside the component. accordion-section .panel-content
, on accordion content, but it wouldn't take effect.color
and background-color
, to be overridable. Pages sets these properties to match that of the page. <slot>