Skip to main content
Module 15 · Lesson 1 of 457/60 in the course~21 min
Module lessons (1/4)

CSS @scope & Donut Scoping (@scope to .slot)

Lesson preview6 hands-on exercises readyModern HTML & CSS · CSS Architecture at Scale: @scope, Scroll Snap & Systems

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 @scope bounds 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 @layer global cascade precedence with local @scope component 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

  1. 1Why Global Descendant Selectors Leak Into Nested Cards
Pro Lesson · CSS Architecture at Scale: @scope, Scroll Snap & Systems

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.