Scope proximity is a cascade criterion for resolving conflicts between scoped rules. When nested scopes target the same element with equal specificity, the nearest scope—the inner scope—wins. Proximity is considered before source order. section 9.3.1
When declarations conflict, apply the relevant cascade criteria in this order:
- Compare selector specificity first; a more specific selector still wins over a less specific selector. section 9.3.1
- If specificity is equal, prefer the declaration from the scope closest to the targeted element in the DOM. section 9.3.1
- Use source order only after scope proximity fails to distinguish the declarations. section 9.3.1
A nested media module
A highlight-block scope colors its headings blue, while a nested media scope also styles its h4 heading. Because both rules target the Strength heading with equal specificity, the inner media scope wins and keeps the heading dark gray. Wrapping the media module in highlight-block makes the DOM relationship that determines the result visible. section 9.3.1
Figure 9.7 Scope proximity is considered after selector specificity but before source order.
Use the cascade flow chart to locate scope proximity between selector specificity and source order. section 9.3.1
