Module lessons (1/4)
CSS @scope & Donut Scoping (@scope to .slot)
Bound component stylesheets strictly between a DOM root and embedded slot boundaries without resorting to BEM clutter or !important.
What you'll learn in this lesson
- Understand how
@scopebounds CSS rules strictly to a DOM subtree root without verbose BEM class prefixes. - Use donut scoping (
@scope (.root) to (.slot)) to stop parent component styles from leaking into nested third-party slots or sub-widgets. - Combine
@layerglobal cascade precedence with local@scopecomponent isolation cleanly.
Overview
Writing .card h2 { color: #0369a1; } looks harmless until a designer drops a dark-themed notification or third-party chart widget inside .card: every descendant <h2> inside that nested child gets hijacked too!
Native CSS @scope eliminates both leaks cleanly with two boundaries:
Sections covered in this lesson
- 1Why Global Descendant Selectors Leak Into Nested Cards
Unlock "CSS @scope & Donut Scoping (@scope to .slot)" and the full Modern HTML & CSS curriculum
Bound component stylesheets strictly between a DOM root and embedded slot boundaries without resorting to BEM clutter or !important.
Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Modern HTML & CSS plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.