The :scope
CSS pseudo-class represents elements that are a reference point, or scope, for selectors to match against.
/* Selects a scoped element */ :scope { background-color: lime; }
Which element(s) :scope
matches depends on the context in which it is used:
- When used at the root level of a stylesheet,
:scope
is equivalent to:root
, which in a regular HTML document matches the<html>
element. - When used inside a
@scope
block,:scope
matches the block's defined scope root. It provides a way to apply styles to the root of the scope from inside the@scope
block itself. - When used within a DOM API call — such as
querySelector()
,querySelectorAll()
,matches()
, orElement.closest()
—:scope
matches the element on which the method was called.