docs.rodeo

MDN Web Docs mirror

CSS scoping

{{CSSRef}} 

The CSS scoping module defines the CSS scoping and encapsulation mechanisms, focusing on the Shadow DOM scoping mechanism.

CSS styles are either global in scope or scoped to a {{Glossary("shadow tree")}} . Globally scoped styles apply to all the elements in the node tree that match the selector, including custom elements in that tree, but not to the shadow trees composing each custom element. Selectors and their associated style definitions don’t bleed between scopes.

Within the CSS of a shadow tree, selectors don’t select elements outside the tree, either in the global scope or in other shadow trees. Each custom element has its own shadow tree, which contains all the components that make up the custom element (but not the custom element, or “host”, itself).

Sometimes it’s useful to be able to style a host from inside the shadow tree context. The CSS scoping module makes this possible by defining selectors that:

Reference

Selectors

Guides

[!NOTE] Despite the name, the {{CSSXref(":scope")}}  pseudo-class, which represents elements that are a reference point (or scope) for selectors to match against, is defined in the Selectors module. It is otherwise unrelated to the CSS scoping module, which is focused on scoping as it pertains to the Shadow DOM scoping mechanism.

Specifications

{{Specifications}} 

See also

In this article

View on MDN