:scope 属于CSS伪类,它将会匹配作为选择符匹配元素的参考点(css的作用域或作用点)。在HTML中,可以使用<style>scoped属性来重新定义新的参考点。如果HTML中没有使用这个属性,那么默认的参考点(css的作用域或作用点)是<html>

/* Selects a scoped element */
:scope {
  background-color: lime;




  The element selected by :scope has a lime background if your browser supports scoped stylesheet.
    <p>Outside scope.</p>
    <style scoped>
      :scope { background-color: lime; }
    <p>Inside scope.</p>
    <p>Outside scope.</p>

Live result


Specification Status Comment
Selectors Level 4
Working Draft Initial definition

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (static profile - stylesheets) (Yes)[1] (Yes)[2] 未实现 15[1] 7.0[1]
In .querySelector/.querySelectorAll (Yes) 32 未实现 15[1] 7.0
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (static profile - stylesheets) ? (Yes)[2] 未实现 未实现 7.0
In .querySelector/.querySelectorAll ? 32 未实现 未实现 7.0

[1] Although Chrome and Safari register a match of the pseudo-class, and therefore apply the CSS rule, they does not yet support style scoping itself, with the consequence that the applied CSS rule floods beyond the intended portion of the document. It, thus, effectively and functionally equals to :root.

[2] Gecko 20 (Firefox 20) and later implement :scope pseudo-classes, but the preference layout.css.scope-pseudo.enabled must be set to true. It is only enabled by default in Nightly and Aurora test versions and since Gecko 32 (Firefox 32).

See also