forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.html
More file actions
1626 lines (1116 loc) · 77 KB
/
Overview.html
File metadata and controls
1626 lines (1116 loc) · 77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>CSS Scoping Module Level 1</title>
<link href="../default.css" rel="stylesheet" type="text/css">
<link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<style>
body {
background: url("https://www.w3.org/StyleSheets/TR/logo-ED") top left no-repeat white;
background-attachment: fixed;
color: black;
font-family: sans-serif;
margin: 0 auto;
max-width: 50em;
padding: 2em 1em 2em 70px;
}
:link { color: #00C; background: transparent }
:visited { color: #609; background: transparent }
a[href]:active { color: #C00; background: transparent }
a[href]:hover { background: #ffa }
a[href] img { border-style: none }
h1, h2, h3, h4, h5, h6 { text-align: left }
h1, h2, h3 { color: #005A9C; }
h1 { font: 170% sans-serif }
h2 { font: 140% sans-serif }
h3 { font: 120% sans-serif }
h4 { font: bold 100% sans-serif }
h5 { font: italic 100% sans-serif }
h6 { font: small-caps 100% sans-serif }
.hide { display: none }
div.head { margin-bottom: 1em }
div.head h1 { margin-top: 2em; clear: both }
div.head table { margin-left: 2em; margin-top: 2em }
p.copyright { font-size: small }
p.copyright small { font-size: small }
pre { margin-left: 2em }
dt { font-weight: bold }
ul.toc, ol.toc {
list-style: none;
}
</style>
</head>
<body class="h-entry">
<div class="head">
<p data-fill-with="logo"><a class="logo" href="http://www.w3.org/">
<img alt="W3C" height="48" src="https://www.w3.org/Icons/w3c_home" width="72">
</a>
</p>
<h1 class="p-name no-ref" id="title">CSS Scoping Module Level 1</h1>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft,
<time class="dt-updated" datetime="2014-12-17">17 December 2014</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:</dt>
<dd><a class="u-url" href="http://dev.w3.org/csswg/css-scoping/">http://dev.w3.org/csswg/css-scoping/</a></dd>
<dt>Latest version:</dt>
<dd><a href="http://www.w3.org/TR/css-scoping-1/">http://www.w3.org/TR/css-scoping-1/</a></dd>
<dt>Feedback:</dt>
<dd><span><a href="mailto:www-style@w3.org?subject=%5Bcss-scoping%5D%20feedback">www-style@w3.org</a> with subject line “<kbd>[css-scoping] <var>… message topic …</var></kbd>” (<a href="http://lists.w3.org/Archives/Public/www-style/" rel="discussion">archives</a>)</span></dd>
<dt>Issue Tracking:</dt>
<dd><a href="https://www.w3.org/Bugs/Public/buglist.cgi?component=Scoping&list_id=47685&product=CSS&resolution=---">Bugzilla</a></dd>
<dd><a href="#issues-index">Inline In Spec</a></dd>
<dt class="editor">Editors:</dt>
<dd class="editor">
<div class="p-author h-card vcard"><a class="p-name fn u-url url" href="http://xanthir.com/contact/">Tab Atkins Jr.</a> (<span class="p-org org">Google</span>)</div>
</dd>
<dd class="editor">
<div class="p-author h-card vcard"><a class="p-name fn u-url url" href="http://fantasai.inkedblade.net/contact">Elika J Etemad</a> (<span class="p-org org">Invited Expert</span>)</div>
</dd>
</dl>
</div>
<div data-fill-with="warning"></div>
<p class="copyright" data-fill-with="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2014 <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="http://www.keio.ac.jp/">Keio</a>, <a href="http://ev.buaa.edu.cn/">Beihang</a>), All Rights Reserved. W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply.
</p>
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
<div class="p-summary" data-fill-with="abstract">
<p>This specification defines various scoping/encapsulation mechanisms for CSS, including scoped styles and the <a class="css" data-link-type="maybe" href="#at-ruledef-scope">@scope</a> rule, Shadow DOM selectors, and page/region-based styling.</p>
<a href="http://www.w3.org/TR/CSS/">CSS</a> is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, in speech, etc.</div>
<h2 class="no-num no-toc no-ref heading settled" id="status"><span class="content">Status of this document</span></h2>
<div data-fill-with="status">
<p>
This is a public copy of the editors’ draft.
It is provided for discussion only and may change at any moment.
Its publication here does not imply endorsement of its contents by W3C.
Don’t cite this document other than as work in progress.
</p>
<p>
The (<a href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public mailing list
<a href="mailto:www-style@w3.org?Subject=%5Bcss-scoping%5D%20PUT%20SUBJECT%20HERE">www-style@w3.org</a>
(see <a href="http://www.w3.org/Mail/Request">instructions</a>)
is preferred for discussion of this specification.
When sending e-mail,
please put the text “css-scoping” in the subject,
preferably like this:
“[css-scoping] <em>…summary of comment…</em>”
</p>
<p>
This document was produced by the <a href="http://www.w3.org/Style/CSS/members">CSS Working Group</a>
(part of the <a href="http://www.w3.org/Style/">Style Activity</a>).
</p>
<p>
This document was produced by a group operating under
the <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent Policy</a>.
W3C maintains a <a href="http://www.w3.org/2004/01/pp-impl/32061/status" rel="disclosure">public list of any patent disclosures</a>
made in connection with the deliverables of the group;
that page also includes instructions for disclosing a patent.
An individual who has actual knowledge of a patent which the individual believes contains <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential Claim(s)</a>
must disclose the information in accordance with <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the W3C Patent Policy</a>.
</p>
<p>
This document is governed by the <a href="http://www.w3.org/2014/Process-20140801/">1 August 2014 W3C Process Document</a>.
</p></div>
<div data-fill-with="at-risk"></div>
<h2 class="no-num no-toc no-ref heading settled" id="contents"><span class="content">Table of Contents</span></h2>
<div data-fill-with="table-of-contents" role="navigation">
<ul class="toc" role="directory">
<li><a href="#intro"><span class="secno">1</span> <span class="content">
Introduction</span></a></li>
<li><a href="#scope"><span class="secno">2</span> <span class="content">
Scoped Styles</span></a>
<ul class="toc">
<li><a href="#scoping-mechanisms"><span class="secno">2.1</span> <span class="content">
Scoping Mechanisms</span></a>
<ul class="toc">
<li><a href="#scoping-markup"><span class="secno">2.1.1</span> <span class="content">
Document Markup for Scoping</span></a></li>
<li><a href="#scope-atrule"><span class="secno">2.1.2</span> <span class="content">
CSS Syntax for Scoping: the <span class="css" data-link-type="maybe" title="@scope">@scope</span> rule</span></a></li>
</ul>
</li>
<li><a href="#scoping-context"><span class="secno">2.2</span> <span class="content">
Querying the Scoping Context</span></a>
<ul class="toc">
<li><a href="#scope-pseudo"><span class="secno">2.2.1</span> <span class="content">
Selecting the Scoping Root: <span class="css" data-link-type="maybe" title=":scope">:scope</span> pseudo-class</span></a></li>
<li><a href="#scope-content-pseudo"><span class="secno">2.2.2</span> <span class="content">
Selecting Outside the Scope: <span class="css">:scope-context()</span> pseudo-class</span></a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#shadow-dom"><span class="secno">3</span> <span class="content">
Shadow Encapsulation</span></a>
<ul class="toc">
<li><a href="#selectors-data-model"><span class="secno">3.1</span> <span class="content">
Shadow DOM Selection Model</span></a>
<ul class="toc">
<li><a href="#host-element-in-tree"><span class="secno">3.1.1</span> <span class="content">
Host Elements in a Shadow Tree</span></a></li>
</ul>
</li>
<li><a href="#selectors"><span class="secno">3.2</span> <span class="content">
Shadow DOM Selectors</span></a>
<ul class="toc">
<li><a href="#host-selector"><span class="secno">3.2.1</span> <span class="content">
Selecting Into the Light: the <span class="css" data-link-type="maybe" title=":host">:host</span>, <span class="css" data-link-type="maybe" title=":host()">:host()</span>, and <span class="css" data-link-type="maybe" title=":host-context()">:host-context()</span> pseudo-classes</span></a></li>
<li><a href="#shadow-pseudoelement"><span class="secno">3.2.2</span> <span class="content">
Selecting Into the Dark: the <span class="css" data-link-type="maybe" title="::shadow">::shadow</span> pseudo-element</span></a></li>
<li><a href="#content-combinator"><span class="secno">3.2.3</span> <span class="content">
Selecting Shadow-Projected Content: the <span class="css" data-link-type="maybe" title="::content">::content</span> pseudo-element</span></a></li>
<li><a href="#deep-combinator"><span class="secno">3.2.4</span> <span class="content">
Selecting Through Shadows: the <span class="css" data-link-type="maybe" title=">>>">>>></span> combinator</span></a></li>
</ul>
</li>
<li><a href="#shadow-cascading"><span class="secno">3.3</span> <span class="content">
Shadow Cascading & Inheritance</span></a>
<ul class="toc">
<li><a href="#cascading"><span class="secno">3.3.1</span> <span class="content">
Cascading</span></a></li>
<li><a href="#inheritance"><span class="secno">3.3.2</span> <span class="content">
Inheritance</span></a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#fragment-scoping"><span class="secno">4</span> <span class="content">
Fragmented Styling</span></a>
<ul class="toc">
<li><a href="#the-region-pseudo-element"><span class="secno">4.1</span> <span class="content">
Region-based Styling: the <span class="css">::region</span> pseudo-element</span></a></li>
</ul>
</li>
<li><a href="#conformance"><span class="secno"></span> <span class="content">
Conformance</span></a>
<ul class="toc">
<li><a href="#conventions"><span class="secno"></span> <span class="content">
Document conventions</span></a></li>
<li><a href="#conformance-classes"><span class="secno"></span> <span class="content">
Conformance classes</span></a></li>
<li><a href="#partial"><span class="secno"></span> <span class="content">
Partial implementations</span></a></li>
<li><a href="#experimental"><span class="secno"></span> <span class="content">
Experimental implementations</span></a></li>
<li><a href="#testing"><span class="secno"></span> <span class="content">
Non-experimental implementations</span></a></li>
</ul>
</li>
<li><a href="#references"><span class="secno"></span> <span class="content">References</span></a>
<ul class="toc">
<li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a></li>
<li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a></li>
</ul>
</li>
<li><a href="#index"><span class="secno"></span> <span class="content">Index</span></a></li>
<li><a href="#issues-index"><span class="secno"></span> <span class="content">Issues Index</span></a></li>
</ul></div>
<main>
<h2 class="heading settled" data-level="1" id="intro"><span class="secno">1. </span><span class="content">
Introduction</span><a class="self-link" href="#intro"></a></h2>
<p>...</p>
<h2 class="heading settled" data-level="2" id="scope"><span class="secno">2. </span><span class="content">
Scoped Styles</span><a class="self-link" href="#scope"></a></h2>
<p><a data-link-type="dfn" href="http://dev.w3.org/csswg/css-cascade-3/#scoped">Scoped</a> style rules apply only within a subtree of a document,
rather than matching against the entire document.
Scoping has two primary effects:</p>
<ul>
<li data-md="">
<p>The selector of the <a data-link-type="dfn" href="http://dev.w3.org/csswg/css-cascade-3/#scoped">scoped</a> style rule is restricted to match only elements within scope.
See <a href="http://www.w3.org/TR/selectors4/#scoping">Scoped Selectors</a> in <a data-biblio-type="informative" data-link-type="biblio" href="#biblio-selectors4" title="SELECTORS4">[SELECTORS4]</a>.</p>
</li>
<li data-md="">
<p>The cascade prioritizes scoped rules over unscoped ones, regardless of specificity.
See <a href="http://www.w3.org/TR/css-cascade/#cascade-scope">Cascading by Scope</a> in <a data-biblio-type="informative" data-link-type="biblio" href="#biblio-css3cascade" title="CSS3CASCADE">[CSS3CASCADE]</a>.</p>
</li></ul>
<h3 class="heading settled" data-level="2.1" id="scoping-mechanisms"><span class="secno">2.1. </span><span class="content">
Scoping Mechanisms</span><a class="self-link" href="#scoping-mechanisms"></a></h3>
<p>Style rules can be scoped using constructs defined in the document language
or using the <a class="css" data-link-type="maybe" href="#at-ruledef-scope">@scope</a> rule in CSS.</p>
<p>“Scoping” consists of three somewhat independent concepts,
which are in practice generally used together:</p>
<ul>
<li data-md="">
<p>A declaration can be scoped to <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scoping-root">scoping root</a>,
which <a href="http://dev.w3.org/csswg/css-cascade/#cascade-scope">affects its cascading behavior</a>. <a data-biblio-type="normative" data-link-type="biblio" href="#biblio-css3cascade" title="CSS3CASCADE">[CSS3CASCADE]</a>
(Alternately, a style rule can be scoped to <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scoping-root">scoping root</a>,
which scopes all of the declarations it contains to that <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scoping-root">scoping root</a>.)</p>
</li>
<li data-md="">
<p>A selector can be either <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scope-contained">scope-contained</a> or <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scope-filtered">scope-filtered</a> to a <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scoping-root">scoping root</a>,
which <a href="http://dev.w3.org/csswg/selectors/#evaluating-selectors">limits what elements it is allowed to match</a>. <a data-biblio-type="normative" data-link-type="biblio" href="#biblio-selectors4" title="SELECTORS4">[SELECTORS4]</a></p>
</li>
<li data-md="">
<p>The <a class="css" data-link-type="maybe" href="http://dev.w3.org/csswg/selectors-4/#scope-pseudo">:scope</a> pseudo-class matches whatever the context sets as the <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scope-element">:scope elements</a>,
and is used by several features, such as relative selectors.
In the absence of any anything explicitly setting the <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scope-element">:scope elements</a> to something,
the <a class="css" data-link-type="maybe" href="http://dev.w3.org/csswg/selectors-4/#scope-pseudo">:scope</a> pseudo-class matches the selector’s <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scoping-root">scoping root</a>.</p>
</li></ul>
<h4 class="heading settled" data-level="2.1.1" id="scoping-markup"><span class="secno">2.1.1. </span><span class="content">
Document Markup for Scoping</span><a class="self-link" href="#scoping-markup"></a></h4>
<p>Document languages may define a mechanism for a stylesheet to be scoped to some element in the document.
For example, in HTML,
a <a data-link-type="element" href="https://html.spec.whatwg.org/#the-style-element">style</a> element with a <a data-link-for="style" data-link-type="element-attr">scoped</a> attribute
defines a stylesheet that is scoped to the <a data-link-type="element" href="https://html.spec.whatwg.org/#the-style-element">style</a> element’s parent element.
<a data-biblio-type="informative" data-link-type="biblio" href="#biblio-html" title="HTML">[HTML]</a></p>
<p>The element that the stylesheet is scoped to
is the <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scoping-root">scoping root</a> for all the style rules in the stylesheet,
and selectors of style rules in the stylesheet
are <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scope-contained">scope-contained</a> to the <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scoping-root">scoping root</a>.</p>
<h4 class="heading settled" data-level="2.1.2" id="scope-atrule"><span class="secno">2.1.2. </span><span class="content">
CSS Syntax for Scoping: the <a class="css" data-link-type="maybe" href="#at-ruledef-scope">@scope</a> rule</span><a class="self-link" href="#scope-atrule"></a></h4>
<p>The <dfn class="css" data-dfn-type="at-rule" data-export="" id="at-ruledef-scope">@scope<a class="self-link" href="#at-ruledef-scope"></a></dfn> at-rule allows authors to create scoped style rules using CSS syntax.
The syntax of the <a class="css" data-link-type="maybe" href="#at-ruledef-scope">@scope</a> rule is:</p>
<pre class="prod">@scope <a class="production" data-link-type="type" href="http://dev.w3.org/csswg/selectors-4/#typedef-selector"><selector></a> {
<a class="production" data-link-type="type" href="http://dev.w3.org/csswg/css-syntax-3/#typedef-stylesheet"><stylesheet></a>
}
</pre>
<p>where the elements matched by the <a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/selectors-4/#typedef-selector"><selector></a>
are <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scoping-root">scoping roots</a> for the style rules in <a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/css-syntax-3/#typedef-stylesheet"><stylesheet></a>,
and selectors of style rules scoped by <a class="css" data-link-type="maybe" href="#at-ruledef-scope">@scope</a> are
<a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scope-contained">scope-contained</a> to their <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scoping-root">scoping root</a>.</p>
<p class="issue" id="issue-5f568f10"><a class="self-link" href="#issue-5f568f10"></a>
This rule makes it very easy for authors to create scoped style sheets,
which could affect the optimization strategies for implementing scoped styles.
</p>
<p>If multiple elements match the <a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/selectors-4/#typedef-selector"><selector></a>,
the <a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/css-syntax-3/#typedef-stylesheet"><stylesheet></a> is effectively duplicated
and scoped independently to each one.
Authors should avoid using overly-generic selectors
as it can have confusing interactions with the cascade.</p>
<div class="example">
A scoped stylesheet is attached not only to the outermost scoping element,
but to all matching elements.
For example, given the style sheet below
<pre>@scope div {
span {
color: blue;
}
}
@scope section {
span {
color: orange;
}
}
</pre>
<p>and the following document fragment</p>
<pre><div>
<section>
<div>
<span>text</span>
</div>
</section>
</div>
</pre>
<p>the text will be blue.</p>
</div>
<p><a class="css" data-link-type="maybe" href="#at-ruledef-scope">@scope</a> rules can be nested.
In this case, just as with the nested style rules,
the selector of an outer <a class="css" data-link-type="maybe" href="#at-ruledef-scope">@scope</a> scope-contains
the selector of the inner one.</p>
<p>The specificity of selectors inside the <a class="css" data-link-type="maybe" href="#at-ruledef-scope">@scope</a> rule is calculated locally:
the selector specifying the scoping element is ignored.
However, because scoped styles override non-scoped styles,
style rules inside the <a class="css" data-link-type="maybe" href="#at-ruledef-scope">@scope</a> will override rules outside of it.</p>
<div class="example">
In the following example, the text would be green:
<pre>@scope aside {
p { color: green; }
}
aside#sidebar p { color: red; }
</pre>
</div>
<p class="issue" id="issue-f07dce09"><a class="self-link" href="#issue-f07dce09"></a>If multiple <a class="css" data-link-type="maybe" href="#at-ruledef-scope">@scope</a> rules apply to an element,
should they be cascaded by specificity?</p>
<h3 class="heading settled" data-level="2.2" id="scoping-context"><span class="secno">2.2. </span><span class="content">
Querying the Scoping Context</span><a class="self-link" href="#scoping-context"></a></h3>
<h4 class="heading settled" data-level="2.2.1" id="scope-pseudo"><span class="secno">2.2.1. </span><span class="content">
Selecting the Scoping Root: <a class="css" data-link-type="maybe" href="http://dev.w3.org/csswg/selectors-4/#scope-pseudo">:scope</a> pseudo-class</span><a class="self-link" href="#scope-pseudo"></a></h4>
<p>In a scoped stylesheet,
the <a class="css" data-link-type="maybe" href="http://dev.w3.org/csswg/selectors-4/#scope-pseudo">:scope</a> pseudo-class,
defined in <a data-biblio-type="informative" data-link-type="biblio" href="#biblio-selectors4" title="SELECTORS4">[SELECTORS4]</a>,
matches the <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scoping-root">scoping root</a>.</p>
<h4 class="heading settled" data-level="2.2.2" id="scope-content-pseudo"><span class="secno">2.2.2. </span><span class="content">
Selecting Outside the Scope: <span class="css">:scope-context()</span> pseudo-class</span><a class="self-link" href="#scope-content-pseudo"></a></h4>
<div class="issue" id="issue-6bd6b9cc"><a class="self-link" href="#issue-6bd6b9cc"></a>
This would be defined similarly to <a class="css" data-link-type="maybe" href="#selectordef-host-context">:host-context()</a>,
but matching the ancestors of the <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#scoping-root">scoping root</a> instead.
<p>However, since for scoped stylesheets you may want the ability to match complex selectors against the outside tree,
rather than a single compound selector,
we may want to instead use a more general mechanism that doesn’t syntactically invert the order of tree elements.</p>
<p>Possible ideas:</p>
<pre>:scope-context(<a class="production" data-link-type="type" href="http://dev.w3.org/csswg/selectors-4/#typedef-selector"><selector></a>) div {...}
scope(<a class="production" data-link-type="type" href="http://dev.w3.org/csswg/selectors-4/#typedef-selector"><selector></a>) div {...}
\scope <a class="production" data-link-type="type" href="http://dev.w3.org/csswg/selectors-4/#typedef-selector"><selector></a>\ div {...}
<a class="production" data-link-type="type" href="http://dev.w3.org/csswg/selectors-4/#typedef-selector"><selector></a> \scope\ div {...}
</pre>
<p>This functionality would replace <span class="css">@global</span>, which is a poor excuse for a selector.</p>
</div>
<h2 class="heading settled" data-level="3" id="shadow-dom"><span class="secno">3. </span><span class="content">
Shadow Encapsulation</span><a class="self-link" href="#shadow-dom"></a></h2>
<p>The Shadow DOM spec augments the DOM with several new concepts,
several of which are relevant to CSS.</p>
<p>A <dfn data-dfn-type="dfn" data-export="" id="shadow-tree">shadow tree<a class="self-link" href="#shadow-tree"></a></dfn> is a document fragment
that can be attached to any element in the DOM.
The root of the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> is a <dfn data-dfn-type="dfn" data-export="" id="shadow-root">shadow root<a class="self-link" href="#shadow-root"></a></dfn>,
a non-element node which is associated with a <a data-link-type="dfn" href="#shadow-host">shadow host</a>.
An element can have any number of <a data-link-type="dfn" href="#shadow-tree">shadow trees</a>,
which are ordered by creation time.
The most recently-created <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> on an element
is the <dfn data-dfn-type="dfn" data-export="" id="youngest-shadow-tree">youngest shadow tree<a class="self-link" href="#youngest-shadow-tree"></a></dfn> for that element.</p>
<p>An element with a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> is a <dfn data-dfn-type="dfn" data-export="" id="shadow-host">shadow host<a class="self-link" href="#shadow-host"></a></dfn>.
It is the <dfn data-dfn-type="dfn" data-export="" id="host-element">host element<a class="self-link" href="#host-element"></a></dfn> for its shadow trees.</p>
<p>The descendants of a <a data-link-type="dfn" href="#shadow-host">shadow host</a>
must not generate boxes in the formatting tree.
Instead, the contents of the <a data-link-type="dfn" href="#youngest-shadow-tree">youngest shadow tree</a> generate boxes
as if they were the contents of the element instead.</p>
<p>In several instances in shadow DOM,
elements don’t have element parents
(instead, they may have a <a data-link-type="dfn" href="#shadow-root">shadow root</a> as parent,
or something else).
An element without a parent,
or whose parent is not an element,
is called a <dfn data-dfn-type="dfn" data-export="" id="top-level-element">top-level element<a class="self-link" href="#top-level-element"></a></dfn>.</p>
<p>While the children of a <a data-link-type="dfn" href="#shadow-host">shadow host</a> do not generate boxes normally,
they can be explicitly pulled into a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> and forced to render normally.
This is done by marking the elements as <dfn data-dfn-type="dfn" data-export="" id="distributed-nodes">distributed nodes<a class="self-link" href="#distributed-nodes"></a></dfn>
for an <dfn data-dfn-type="dfn" data-export="" id="insertion-point">insertion point<a class="self-link" href="#insertion-point"></a></dfn> element.</p>
<p>This specification does not define how to mark elements as <a data-link-type="dfn" href="#distributed-nodes">distributed nodes</a>,
instead leaving that to the Shadow DOM spec.
At the time this spec is written, however,
only <a data-link-type="element">content</a> elements in a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> can be <a data-link-type="dfn" href="#insertion-point">insertion points</a>.</p>
<p>An <a data-link-type="dfn" href="#insertion-point">insertion point</a> must not generate any boxes.
Instead, its <a data-link-type="dfn" href="#distributed-nodes">distributed nodes</a> generate boxes as normal,
as if they all replaced the <a data-link-type="dfn" href="#insertion-point">insertion point</a> in-place.
<span class="note" role="note">(Akin to the behavior of <a class="css" data-link-type="propdesc" href="http://dev.w3.org/csswg/css-display-3/#propdef-display-outside" title="display-outside">display-outside: contents</a>.)</span></p>
<h3 class="heading settled" data-level="3.1" id="selectors-data-model"><span class="secno">3.1. </span><span class="content">
Shadow DOM Selection Model</span><a class="self-link" href="#selectors-data-model"></a></h3>
<p>Elements in the DOM
have zero or more <a data-link-type="dfn" href="#shadow-tree">shadow trees</a>
and zero or more <a data-link-type="dfn" href="#distributed-nodes">distributed nodes</a>.</p>
<p class="note" role="note">Note: The "descendants" of an element
are based on the children of the element,
which does not include the <a data-link-type="dfn" href="#shadow-tree">shadow trees</a> or <a data-link-type="dfn" href="#distributed-nodes">distributed nodes</a> of the element.</p>
<p>When a selector is matched against a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>,
the <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#selector-match-list">selector match list</a>
is initially the <a data-link-type="dfn" href="#shadow-host">shadow host</a>,
followed by all the <a data-link-type="dfn" href="#top-level-element">top-level elements</a> of the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>
and their descendants,
ordered by a pre-order traversal.</p>
<h4 class="heading settled" data-level="3.1.1" id="host-element-in-tree"><span class="secno">3.1.1. </span><span class="content">
Host Elements in a Shadow Tree</span><a class="self-link" href="#host-element-in-tree"></a></h4>
<p>A <a data-link-type="dfn" href="#shadow-host">shadow host</a> is outside of the <a data-link-type="dfn" href="#shadow-tree">shadow trees</a> it hosts,
but it is sometimes useful to be able to style it from inside the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> context.</p>
<p>For the purpose of Selectors,
a <a data-link-type="dfn" href="#host-element">host element</a> also appears in each of its <a data-link-type="dfn" href="#shadow-tree">shadow trees</a>,
with the contents of the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> treated as its children.
If an element has multiple <a data-link-type="dfn" href="#shadow-tree">shadow trees</a>,
it appears in each <a data-link-type="dfn" href="#shadow-tree">shadow tree’s</a> context independently;
each <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> sees <em>itself</em> as the contents of the <a data-link-type="dfn" href="#host-element">host element</a>,
not the other <a data-link-type="dfn" href="#shadow-tree">shadow trees</a>.</p>
<p>The <a data-link-type="dfn" href="#host-element">host element</a> is not selectable by <strong>any means</strong>
except for the <a class="css" data-link-type="maybe" href="#selectordef-host">:host</a> and <a class="css" data-link-type="maybe" href="#selectordef-host-context">:host-context()</a> pseudo-classes.
That is, in this context the <a data-link-type="dfn" href="#shadow-host">shadow host</a>
has no tagname, ID, classes, or attributes,
and the only additional information is has is that the <a class="css" data-link-type="maybe" href="#selectordef-host">:host</a> pseudo-class matches it.
In particular, the <a data-link-type="dfn" href="#host-element">host element</a> isn’t matched by the <span class="css">*</span> selector either.</p>
<details class="why">
<summary>Why is the shadow host so weird?</summary>
<p>The <a data-link-type="dfn" href="#shadow-host">shadow host</a> lives outside the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>,
and its markup is in control of the page author,
not the component author.</p>
<p>It would not be very good if a component used a particular class name
internally in a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>,
and the page author using the component accidentally <em>also</em>
used the the same class name and put it on the <a data-link-type="dfn" href="#host-element">host element</a>.
Such a situation would result in accidental styling
that is impossible for the component author to predict,
and confusing for the page author to debug.</p>
<p>However, there are still some reasonable use-cases for letting a stylesheet in a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>
style its <a data-link-type="dfn" href="#host-element">host element</a>.
So, to allow this situation but prevent accidental styling,
the <a data-link-type="dfn" href="#host-element">host element</a> appears but is completely featureless
and unselectable except through <a class="css" data-link-type="maybe" href="#selectordef-host">:host</a>.</p>
</details>
<h3 class="heading settled" data-level="3.2" id="selectors"><span class="secno">3.2. </span><span class="content">
Shadow DOM Selectors</span><a class="self-link" href="#selectors"></a></h3>
<p>Shadow DOM defines a few new selectors
to help select elements in useful way related to Shadow DOM.</p>
<p class="issue" id="issue-dea392ae"><a class="self-link" href="#issue-dea392ae"></a>This section is still under discussion.
Feedback and advice on intuitive syntax for the following functionality
would be appreciated.</p>
<h4 class="heading settled" data-level="3.2.1" id="host-selector"><span class="secno">3.2.1. </span><span class="content">
Selecting Into the Light: the <a class="css" data-link-type="maybe" href="#selectordef-host">:host</a>, <a class="css" data-link-type="maybe" href="#selectordef-host-function">:host()</a>, and <a class="css" data-link-type="maybe" href="#selectordef-host-context">:host-context()</a> pseudo-classes</span><a class="self-link" href="#host-selector"></a></h4>
<p>The <dfn class="css" data-dfn-type="selector" data-export="" id="selectordef-host">:host<a class="self-link" href="#selectordef-host"></a></dfn> pseudo-class,
when evaluated in the context of a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>,
matches the <a data-link-type="dfn" href="#shadow-tree">shadow tree’s</a> <a data-link-type="dfn" href="#host-element">host element</a>.
In any other context,
it matches nothing.</p>
<p>The <dfn class="css" data-dfn-type="selector" data-export="" id="selectordef-host-function">:host()<a class="self-link" href="#selectordef-host-function"></a></dfn> function pseudo-class
has the syntax:</p>
<pre>:host( <a class="production" data-link-type="type" href="http://dev.w3.org/csswg/selectors-4/#typedef-compound-selector"><compound-selector></a> )</pre>
<p>When evaluated in the context of a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>,
it matches the <a data-link-type="dfn" href="#shadow-tree">shadow tree’s</a> <a data-link-type="dfn" href="#host-element">host element</a>
if the <a data-link-type="dfn" href="#host-element">host element</a>,
in its normal context,
matches the selector argument.
In any other context,
it matches nothing.</p>
<div class="example">
For example, say you had a component with a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> like the following:
<pre><x-foo class="foo">
<"shadow tree">
<div class="foo">...</div>
</>
</x-foo>
</pre>
<p>For a stylesheet within the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>:</p>
<ul>
<li data-md="">
<p><a class="css" data-link-type="maybe" href="#selectordef-host">:host</a> matches the <code><x-foo></code> element.</p>
</li>
<li data-md="">
<p><span class="css">x-foo</span> matches nothing.</p>
</li>
<li data-md="">
<p><span class="css">.foo</span> matches only the <code><div></code> element.</p>
</li>
<li data-md="">
<p><span class="css">.foo:host</span> matches nothing</p>
</li>
<li data-md="">
<p><span class="css">:host(.foo)</span> matches the <code><x-foo></code> element.</p>
</li>
<li data-md=""> </li></ul>
</div>
<p>Ordinary, selectors within a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>
can’t see elements outside the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> at all.
Sometimes, however, it’s useful to select an ancestor that lies somewhere outside the shadow tree,
above it in the document.</p>
<div class="example">
For example, a group of components can define a handful of color themes
they they know how to respond to.
Page authors could opt into a particular theme
by adding a specific class to the components,
or higher up in the document.
</div>
<p>The <dfn class="css" data-dfn-type="selector" data-export="" id="selectordef-host-context">:host-context()<a class="self-link" href="#selectordef-host-context"></a></dfn> functional pseudo-class tests whether there is an ancestor,
outside the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>,
which matches a particular selector.
Its syntax is:</p>
<pre>:host-context( <a class="production" data-link-type="type" href="http://dev.w3.org/csswg/selectors-4/#typedef-compound-selector"><compound-selector></a> )</pre>
<p>When evaluated in the context of a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>,
the <a class="css" data-link-type="maybe" href="#selectordef-host-context">:host-context()</a> pseudo-class matches the <a data-link-type="dfn" href="#host-element">host element</a>,
if the <a data-link-type="dfn" href="#host-element">host element</a> or one of its ancestors matches the provided <a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/selectors-4/#typedef-compound-selector"><compound-selector></a>.
For the purpose of this pseudo-class,
the "ancestor" of an element is:</p>
<dl>
<dt data-md="">
<p>if the element is a <a data-link-type="dfn" href="#distributed-nodes">distributed node</a></p>
</dt>
<dd data-md="">
<p>the <a data-link-type="element">content</a> element it is ultimately distributed to.</p>
</dd>
<dt data-md="">
<p>if the element is a top-most element in a shadow tree</p>
</dt>
<dd data-md="">
<p>the <a data-link-type="dfn" href="#host-element">host element</a></p>
</dd>
<dt data-md="">
<p>otherwise</p>
</dt>
<dd data-md="">
<p>the element’s parent,
if it has one.</p>
</dd></dl>
<p class="note" role="note">Note: This means that the selector pierces through shadow boundaries on the way up,
looking for elements that match its argument,
until it reaches the document root.</p>
<h4 class="heading settled" data-level="3.2.2" id="shadow-pseudoelement"><span class="secno">3.2.2. </span><span class="content">
Selecting Into the Dark: the <a class="css" data-link-type="maybe" href="#selectordef-shadow">::shadow</a> pseudo-element</span><a class="self-link" href="#shadow-pseudoelement"></a></h4>
<p>If an element has at least one <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>,
the <dfn class="css" data-dfn-type="selector" data-export="" id="selectordef-shadow">::shadow<a class="self-link" href="#selectordef-shadow"></a></dfn> pseudo-element matches the <a data-link-type="dfn" href="#shadow-root">shadow roots</a> themselves.
In HTML, the <a data-link-type="dfn" href="#shadow-root">shadow root</a> is represented by <a class="idl-code" data-link-type="interface">ShadowRoot</a> objects.</p>
<p>The <a class="css" data-link-type="maybe" href="#selectordef-shadow">::shadow</a> pseudo-element must not generate boxes,
unless specified otherwise in another specification.
However, for the purpose of Selectors,
the <a class="css" data-link-type="maybe" href="#selectordef-shadow">::shadow</a> pseudo-element is considered to be the root of the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>,
with the <a data-link-type="dfn" href="#top-level-element">top-level elements</a> in the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> the direct children of the <a class="css" data-link-type="maybe" href="#selectordef-shadow">::shadow</a> pseudo-element.</p>
<div class="example">
For example, say you had a component with a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> like the following:
<pre><x-foo>
<"shadow tree">
<div>
<span id="not-top">...</span>
</div>
<span id="top">...</span>
</>
</x-foo>
</pre>
<p>For a stylesheet in the outer document,
<span class="css">x-foo::shadow > span</span> matches <span class="css">#top</span>,
but not <span class="css">#not-top</span>,
because it’s not a <a data-link-type="dfn" href="#top-level-element">top-level element</a> in the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>.</p>
<p>If one wanted to target <span class="css">#not-top</span>,
one way to do it would be with <span class="css">x-foo::shadow > div > span</span>.
However, this introduces a strong dependency on the internal structure of the component;
in most cases, it’s better to use the descendant combinator,
like <span class="css">x-foo::shadow span</span>,
to select all the elements of some type in the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>.</p>
</div>
<div class="example">
If an element has multiple <a data-link-type="dfn" href="#shadow-tree">shadow trees</a>,
a <a class="css" data-link-type="maybe" href="#selectordef-shadow">::shadow</a> pseudo-element selects <em>all</em> of the corresponding <a data-link-type="dfn" href="#shadow-root">shadow roots</a>.
<p>Similarly,
inside of a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>,
a selector like <span class="css">:host::shadow div</span> selects the <a data-link-type="element" href="https://html.spec.whatwg.org/#the-div-element">div</a> elements in <em>all</em> the <a data-link-type="dfn" href="#shadow-tree">shadow trees</a> on the element,
not just the one containing that selector.</p>
</div>
<h4 class="heading settled" data-level="3.2.3" id="content-combinator"><span class="secno">3.2.3. </span><span class="content">
Selecting Shadow-Projected Content: the <a class="css" data-link-type="maybe" href="#selectordef-content">::content</a> pseudo-element</span><a class="self-link" href="#content-combinator"></a></h4>
<p>The <dfn class="css" data-dfn-type="selector" data-export="" id="selectordef-content">::content<a class="self-link" href="#selectordef-content"></a></dfn> pseudo-element matches the list of <a data-link-type="dfn" href="#distributed-nodes">distributed nodes</a> itself,
on elements that have them.</p>
<p class="issue" id="issue-a514442b"><a class="self-link" href="#issue-a514442b"></a>
<a class="css" data-link-type="maybe" href="#selectordef-content">::content</a> is a confusingly general name for something that is specific
to the projected content of a shadow tree.
</p>
<p>The <a class="css" data-link-type="maybe" href="#selectordef-content">::content</a> pseudo-element must not generate boxes,
unless specified otherwise in another specification.
However, for the purpose of Selectors,
the <a class="css" data-link-type="maybe" href="#selectordef-content">::content</a> pseudo-element is considered to be the parent of the <a data-link-type="dfn" href="#distributed-nodes">distributed nodes</a>.</p>
<div class="example">
For example, say you had a component with both children and a shadow tree,
like the following:
<pre><x-foo>
<div id="one" class="foo">...</div>
<div id="two">...</div>
<div id="three" class="foo">
<div id="four">...</div>
</div>
<"shadow tree">
<div id="five">...</div>
<div id="six">...</div>
<content select=".foo"></content>
</"shadow tree">
</x-foo>
</pre>
<p>For a stylesheet within the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>,
a selector like <span class="css">::content div</span>
selects <span class="css">#one</span>, <span class="css">#three</span>, and <span class="css">#four</span>,
as they’re the elements distributed by the sole <a data-link-type="element">content</a> element,
but not <span class="css">#two</span>.</p>
<p>If only the <a data-link-type="dfn" href="#top-level-element">top-level elements</a> distributed the <a data-link-type="element">content</a> element are desired,
a <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#child-combinator">child combinator</a> can be used,
like <span class="css">::content > div</span>,
which will exclude <span class="css">#four</span>
as it’s not treated as a child of the <a class="css" data-link-type="maybe" href="#selectordef-content">::content</a> pseudo-element.</p>
<p class="note" role="note">Note: Note that a selector like <span class="css">::content div</span>
is equivalent to <span class="css">*::content div</span>,
where the <span class="css">*</span> selects many more elements that just the <a data-link-type="element">content</a> element.
However, since only the <a data-link-type="element">content</a> element has <a data-link-type="dfn" href="#distributed-nodes">distributed nodes</a>,
it’s the only element that has a <a class="css" data-link-type="maybe" href="#selectordef-content">::content</a> pseudo-element as well.</p>
</div>
<h4 class="heading settled" data-level="3.2.4" id="deep-combinator"><span class="secno">3.2.4. </span><span class="content">
Selecting Through Shadows: the <a class="css" data-link-type="maybe" href="#selectordef-shadow-piercing-descendant-combinator">>>></a> combinator</span><a class="self-link" href="#deep-combinator"></a></h4>
<p>When a <dfn class="css" data-dfn-type="selector" data-export="" id="selectordef-shadow-piercing-descendant-combinator">>>><a class="self-link" href="#selectordef-shadow-piercing-descendant-combinator"></a></dfn> combinator
(or <dfn data-dfn-type="dfn" data-export="" id="shadow-piercing-descendant-combinator">shadow-piercing descendant combinator<a class="self-link" href="#shadow-piercing-descendant-combinator"></a></dfn>)
is encountered in a selector,
replace every element in the <a data-link-type="dfn" href="http://dev.w3.org/csswg/selectors-4/#selector-match-list">selector match list</a>
with every element reachable from the original element
by traversing any number of child lists or shadow trees.</p>
<div class="example">
For example, say you had a component with a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> like the following:
<pre><x-foo>
<"shadow tree">
<div>
<span id="not-top">...</span>
</div>
<span id="top">...</span>
<x-bar>
<"shadow tree">
<span id="nested">...</span>
</>
</x-bar>
</>
</x-foo>
</pre>
<p>For a stylesheet in the outer document,
the selector <span class="css">x-foo >>> span</span>
selects all three of <code><span></code> elements:
<span class="css">#top</span>, <span class="css">#not-top</span>, <em>and</em> <span class="css">#nested</span>.</p>
</div>
<h3 class="heading settled" data-level="3.3" id="shadow-cascading"><span class="secno">3.3. </span><span class="content">
Shadow Cascading & Inheritance</span><a class="self-link" href="#shadow-cascading"></a></h3>
<h4 class="heading settled" data-level="3.3.1" id="cascading"><span class="secno">3.3.1. </span><span class="content">
Cascading</span><a class="self-link" href="#cascading"></a></h4>
<p>To address the desired cascading behavior of rules targetting elements in shadow roots,
this specification extends the <a href="http://dev.w3.org/csswg/css-cascade/#cascading">cascade order</a>
defined in the Cascade specification. <a data-biblio-type="normative" data-link-type="biblio" href="#biblio-css3cascade" title="CSS3CASCADE">[CSS3CASCADE]</a></p>
<p>An additional cascade criteria must be added,
between Origin and Scope,
called Shadow Tree.</p>
<ul>
<li data-md="">
<p>When comparing two declarations,
if one of them is in a <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>
and the other is in a document that contains that <a data-link-type="dfn" href="#shadow-tree">shadow tree</a>,
then for normal rules the declaration from the outer document wins,
and for important rules the declaration from the <a data-link-type="dfn" href="#shadow-tree">shadow tree</a> wins.</p>
<p class="note" role="note">Note: This is the <em>opposite</em> of how scoped styles work.</p>
</li>
<li data-md="">
<p>When comparing two declarations,