A CSS-focused interactive reference for styling web components. Each section demonstrates a specific styling technique with a live demo and code snippet.
- The Shadow Boundary — What the shadow boundary blocks and what passes through, with a side-by-side light DOM vs shadow DOM comparison
- :host — Styling the host element from inside shadow DOM, including attribute-driven variants and pseudo-states
- :host-context() — Reacting to ancestor classes with interactive toggles
- CSS Custom Properties — The main theming escape hatch, with live color/size controls that update the component in real time
- ::part() — Styling named internals from outside the shadow boundary, including what combinators work and which don't
- exportparts — Forwarding parts through nested shadow boundaries
- ::slotted() — Styling projected content, with specificity notes and the top-level-only limitation
- Inherited Properties — Which CSS properties cross the shadow boundary automatically and how to block them with
all: initial - Adopted / Constructable Stylesheets — Sharing a single
CSSStyleSheetacross multiple shadow roots with live mutation - <link> Inside Shadow DOM — Loading external stylesheets into a shadow root and FOUC considerations
- :defined and FOUC Prevention — Styling elements before their JS loads with
:not(:defined) - Container Queries in Shadow DOM — Using
@containerinside shadow DOM with a resizable demo - What Doesn't Work — Common mistakes that fail silently
Includes a dark mode toggle that demonstrates CSS custom property theming across all components.
- Vanilla JavaScript custom elements (no frameworks or libraries)
- Vite dev server
- Plain CSS
npm install
npm run devOpen http://localhost:5173 in your browser.
npm run buildOutput goes to dist/.