-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.html
1137 lines (936 loc) · 75.6 KB
/
Overview.html
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=http://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 heading" id=subtitle><span class=content>Editor’s Draft,
<span class=dt-updated><span class=value-title title=20140409>9 April 2014</span></span></span></h2>
<div data-fill-with=spec-metadata><dl><dt>This version:<dd><a class=u-url href=http://dev.w3.org/csswg/css-scoping/>http://dev.w3.org/csswg/css-scoping/</a><dt>Latest version:<dd><a href=http://www.w3.org/TR/css-scoping-1/>http://www.w3.org/TR/css-scoping-1/</a><dt>Editor’s Draft:<dd><a href=http://dev.w3.org/csswg/css-scoping/>http://dev.w3.org/csswg/css-scoping/</a>
<dt>Feedback:</dt>
<dd><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>)<dt>Test Suite:<dd>None Yet<dt>Editors:
<dd 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>)<dd 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>)<dt>Date:<dd>2014-04-03</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 heading" id=abstract><span class=content>Abstract</span></h2>
<p class=p-summary data-fill-with=abstract>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 title=@scope>@scope</a> rule, Shadow DOM selectors, and page/region-based styling.
<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.</p>
<h2 class="no-num no-toc no-ref heading settled heading" 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>
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>
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>
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>.</div>
<div data-fill-with=at-risk></div>
<h2 class="no-num no-toc no-ref heading settled heading" id=contents><span class=content>Table of Contents</span></h2>
<div data-fill-with=table-of-contents><ul class=toc>
<li><a href=#intro><span class=secno>1</span> Introduction</a>
<li><a href=#scope><span class=secno>2</span> Scoped Styles</a>
<ul class=toc>
<li><a href=#scoping-mechanisms><span class=secno>2.1</span> Scoping Mechanisms</a>
<ul class=toc>
<li><a href=#scoping-markup><span class=secno>2.1.1</span> Document Markup for Scoping</a>
<li><a href=#scope-atrule><span class=secno>2.1.2</span> CSS Syntax for Scoping: the <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> rule</a></ul>
<li><a href=#scoping-context><span class=secno>2.2</span> Querying the Scoping Context</a>
<ul class=toc>
<li><a href=#scope-pseudo><span class=secno>2.2.1</span> Selecting the Scoping Root: <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/selectors-4/#scope-pseudo title=:scope>:scope</a> pseudo-class</a>
<li><a href=#scope-content-pseudo><span class=secno>2.2.2</span> Selecting Outside the Scope: <span class=css data-link-type=maybe title=:scope-context()>:scope-context()</span> pseudo-class</a></ul></ul>
<li><a href=#shadow-dom><span class=secno>3</span> Shadow Encapsulation</a>
<ul class=toc>
<li><a href=#selectors-data-model><span class=secno>3.1</span> Shadow DOM Selection Model</a>
<ul class=toc>
<li><a href=#host-element><span class=secno>3.1.1</span> Host Elements in a Shadow Tree</a></ul>
<li><a href=#selectors><span class=secno>3.2</span> Shadow DOM Selectors</a>
<ul class=toc>
<li><a href=#host-selector><span class=secno>3.2.1</span> Selecting Into the Light: the <a class=css data-link-type=maybe href=#selectordef-host0 title=:host>:host</a>, <a class=css data-link-type=maybe href=#selectordef-host title=:host()>:host()</a>, and <a class=css data-link-type=maybe href=#selectordef-host-context title=:host-context()>:host-context()</a> pseudo-classes</a>
<li><a href=#shadow-pseudoelement><span class=secno>3.2.2</span> Selecting Into the Dark: the <a class=css data-link-type=maybe href=#selectordef-shadow title=::shadow>::shadow</a> pseudo-element</a>
<li><a href=#content-combinator><span class=secno>3.2.3</span> Selecting Shadow-Projected Content: the <a class=css data-link-type=maybe href=#selectordef-content title=::content>::content</a> pseudo-element</a>
<li><a href=#deep-combinator><span class=secno>3.2.4</span> Selecting Through Shadows: the <a class=css data-link-type=maybe href=#selectordef-deep title=/deep/>/deep/</a> combinator</a></ul>
<li><a href=#shadow-cascading><span class=secno>3.3</span> Shadow Cascading & Inheritance</a>
<ul class=toc>
<li><a href=#cascading><span class=secno>3.3.1</span> Cascading</a>
<li><a href=#inheritance><span class=secno>3.3.2</span> Inheritance</a></ul></ul>
<li><a href=#fragment-scoping><span class=secno>4</span> Fragmented Styling</a>
<ul class=toc>
<li><a href=#the-region-pseudo-element><span class=secno>4.1</span> Region-based Styling: the <span class=css data-link-type=maybe title=::region>::region</span> pseudo-element</a></ul>
<li><a href=#conformance><span class=secno></span> Conformance</a>
<ul class=toc>
<li><a href=#conventions><span class=secno></span> Document conventions</a>
<li><a href=#conformance-classes><span class=secno></span> Conformance classes</a>
<li><a href=#partial><span class=secno></span> Partial implementations</a>
<li><a href=#experimental><span class=secno></span> Experimental implementations</a>
<li><a href=#testing><span class=secno></span> Non-experimental implementations</a></ul>
<li><a href=#references><span class=secno></span> References</a>
<ul class=toc>
<li><a href=#normative><span class=secno></span> Normative References</a>
<li><a href=#informative><span class=secno></span> Informative References</a></ul>
<li><a href=#index><span class=secno></span> Index</a>
<li><a href=#property-index><span class=secno></span> Property index</a>
<li><a href=#issues-index><span class=secno></span>Issues Index</a></ul></div>
<h2 class="heading settled heading" data-level=1 id=intro><span class=secno>1 </span><span class=content>
Introduction</span><a class=self-link href=#intro></a></h2>
<p> ...
<h2 class="heading settled heading" 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 title=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:
<ul>
<li>The selector of the <a data-link-type=dfn href=http://dev.w3.org/csswg/css-cascade-3/#scoped title=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=#selectors4 title=selectors4>[SELECTORS4]</a>.
<li>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=#css3cascade title=css3cascade>[CSS3CASCADE]</a>.
</ul>
<h3 class="heading settled heading" 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 title=@scope>@scope</a> rule in CSS.
<p> “Scoping” consists of three somewhat independent concepts,
which are in practice generally used together:
<p> <ul>
<li>
A declaration can be scoped to <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scoping-root title="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=#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 title="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 title="scoping root">scoping root</a>.)
<li>
A selector can be either <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scope-contained- title=scope-contained>scope-contained</a> or <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scope-filtered- title=scope-filtered>scope-filtered</a> to a <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scoping-root title="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=#selectors4 title=selectors4>[SELECTORS4]</a>
<li>
The <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/selectors-4/#scope-pseudo title=:scope>:scope</a> pseudo-class matches whatever the context sets as the <a data-link-type=dfn title=":scope elements">: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 title=":scope elements">:scope elements</a> to something,
the <a class=css data-link-type=maybe href=http://dev.w3.org/csswg/selectors-4/#scope-pseudo title=:scope>:scope</a> pseudo-class matches the selector’s <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scoping-root title="scoping root">scoping root</a>.
</ul>
<h4 class="heading settled heading" 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=http://www.w3.org/html/wg/drafts/html/CR/document-metadata.html#the-style-element title=style>style</a> element with a <a data-link-for=style data-link-type=element-attr title=scoped>scoped</a> attribute
defines a stylesheet that is scoped to the <a data-link-type=element href=http://www.w3.org/html/wg/drafts/html/CR/document-metadata.html#the-style-element title=style>style</a> element’s parent element.
<a data-biblio-type=informative data-link-type=biblio href=#html title=html>[HTML]</a>
<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 title="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- title=scope-contained>scope-contained</a> to the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scoping-root title="scoping root">scoping root</a>.
<h4 class="heading settled heading" 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 title=@scope>@scope</a> rule</span><a class=self-link href=#scope-atrule></a></h4>
<p> The <dfn class=css-code 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 title=@scope>@scope</a> rule is:
<pre class=prod>@scope <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-selector title="<selector>"><selector></a> {
<a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-syntax-3/#typedef-stylesheet title="<stylesheet>"><stylesheet></a>
}
</pre>
<p> where the elements matched by the <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-selector title="<selector>"><selector></a>
are <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scoping-root title="scoping roots">scoping roots</a> for the style rules in <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-syntax-3/#typedef-stylesheet title="<stylesheet>"><stylesheet></a>,
and selectors of style rules scoped by <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> are
<a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scope-contained- title=scope-contained>scope-contained</a> to their <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scoping-root title="scoping root">scoping root</a>.
<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> If multiple elements match the <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-selector title="<selector>"><selector></a>,
the <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/css-syntax-3/#typedef-stylesheet title="<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.
<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
<pre><div>
<section>
<div>
<span>text</span>
</div>
</section>
</div>
</pre>
<p> the text will be blue.
</div>
<p> <a class=css data-link-type=maybe href=#at-ruledef-scope title=@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 title=@scope>@scope</a> scope-contains
the selector of the inner one.
<p> The specificity of selectors inside the <a class=css data-link-type=maybe href=#at-ruledef-scope title=@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 title=@scope>@scope</a> will override rules outside of it.
<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-5c7571b6><a class=self-link href=#issue-5c7571b6></a>
If multiple <a class=css data-link-type=maybe href=#at-ruledef-scope title=@scope>@scope</a> rules apply to an element,
should they be cascaded by specificity?
<h3 class="heading settled heading" 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 heading" 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 title=:scope>: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 title=:scope>:scope</a> pseudo-class,
defined in <a data-biblio-type=informative data-link-type=biblio href=#selectors4 title=selectors4>[SELECTORS4]</a>,
matches the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#scoping-root title="scoping root">scoping root</a>.
<h4 class="heading settled heading" 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 data-link-type=maybe title=:scope-context()>:scope-context()</span> pseudo-class</span><a class=self-link href=#scope-content-pseudo></a></h4>
<div class=issue id=issue-aecbd194><a class=self-link href=#issue-aecbd194></a>
This would be defined similarly to <a class=css data-link-type=maybe href=#selectordef-host-context title=: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 title="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> Possible ideas:
<pre>:scope-context(<a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-selector title="<selector>"><selector></a>) div {...}
scope(<a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-selector title="<selector>"><selector></a>) div {...}
\scope <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-selector title="<selector>"><selector></a>\ div {...}
<a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-selector title="<selector>"><selector></a> \scope\ div {...}
</pre>
<p> This functionality would replace <span class=css data-link-type=maybe title=@global>@global</span>, which is a poor excuse for a selector.
</div>
<h2 class="heading settled heading" 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> 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 title="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 title="shadow host">shadow host</a>.
An element can have any number of <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a>,
which are ordered by creation time.
The most recently-created <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> on an element
is the <dfn data-dfn-type=dfn data-export="" id=active-shadow-tree>active shadow tree<a class=self-link href=#active-shadow-tree></a></dfn> for that element.
<p> An element with a <a data-link-type=dfn href=#shadow-tree title="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-element0>host element<a class=self-link href=#host-element0></a></dfn> for its shadow trees.
<p> The descendants of a <a data-link-type=dfn href=#shadow-host title="shadow host">shadow host</a>
must not generate boxes in the formatting tree.
Instead, the contents of the <a data-link-type=dfn href=#active-shadow-tree title="active shadow tree">active shadow tree</a> generate boxes
as if they were the contents of the element instead.
<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 title="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> While the children of a <a data-link-type=dfn href=#shadow-host title="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 title="shadow tree">shadow tree</a> and forced to render normally.
This is done by assigning the elements to a <dfn data-dfn-type=dfn data-export="" id=distribution-list>distribution list<a class=self-link href=#distribution-list></a></dfn>.
An element with a <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a> is an <dfn data-dfn-type=dfn data-export="" id=insertion-point>insertion point<a class=self-link href=#insertion-point></a></dfn>.
<p> This specification does not define how to assign elements to a <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a>,
instead leaving that to the Shadow DOM spec.
At the time this spec is written, however,
only <a data-link-type=element title=content>content</a> elements in a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> can have <a data-link-type=dfn href=#distribution-list title="distribution lists">distribution lists</a>.
<p> An <a data-link-type=dfn href=#insertion-point title="insertion point">insertion point</a> must not generate any boxes.
Instead, the elements in its <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a> generate boxes as normal,
as if they all replaced the <a data-link-type=dfn href=#insertion-point title="insertion point">insertion point</a> in-place.
<span class=note>(Akin to the behavior of <a class=css data-link-type=propdesc href=http://dev.w3.org/csswg/css-display-3/#propdef-display-box title=display-box>display-box: contents</a>.)</span>
<h3 class="heading settled heading" 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 <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#element-tree title="element tree">element tree</a>
additionally have zero or more <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a>
and zero or one <a data-link-type=dfn href=#distribution-list title="distribution lists">distribution lists</a>.
<p class=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 title="shadow trees">shadow trees</a> or <a data-link-type=dfn href=#distribution-list title="distribution lists">distribution lists</a> of the element.
<p> When a selector is matched against a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>,
the <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#initial-selector-match-list title="initial selector match list">initial selector match list</a>
is the <a data-link-type=dfn href=#shadow-host title="shadow host">shadow host</a>,
followed by all the <a data-link-type=dfn href=#top-level-element title="top-level elements">top-level elements</a> of the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>
and their descendants,
ordered by a pre-order traversal.
<h4 class="heading settled heading" data-level=3.1.1 id=host-element><span class=secno>3.1.1 </span><span class=content>
Host Elements in a Shadow Tree</span><a class=self-link href=#host-element></a></h4>
<p> A <a data-link-type=dfn href=#shadow-host title="shadow host">shadow host</a> is outside of the <a data-link-type=dfn href=#shadow-tree title="shadow trees">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 title="shadow tree">shadow tree</a> context.
<p> For the purpose of Selectors,
a <a data-link-type=dfn href=#host-element0 title="host element">host element</a> also appears in each of its <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a>,
with the contents of the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> treated as its children.
If an element has multiple <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a>,
it appears in each <a data-link-type=dfn href=#shadow-tree title="shadow tree’s">shadow tree’s</a> context independently;
each <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> sees <em>itself</em> as the contents of the <a data-link-type=dfn href=#host-element0 title="host element">host element</a>,
not the other <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a>.
<p> The <a data-link-type=dfn href=#host-element0 title="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-host0 title=:host>:host</a> and <a class=css data-link-type=maybe href=#selectordef-host-context title=:host-context()>:host-context()</a> pseudo-classes.
That is, in this context the <a data-link-type=dfn href=#shadow-host title="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-host0 title=:host>:host</a> pseudo-class matches it.
In particular, the <a data-link-type=dfn href=#host-element0 title="host element">host element</a> isn’t matched by the <span class=css data-link-type=maybe title=*>*</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 title="shadow host">shadow host</a> lives outside the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>,
and its markup is in control of the page author,
not the component author.
<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 title="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-element0 title="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> However, there are still some reasonable use-cases for letting a stylesheet in a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>
style its <a data-link-type=dfn href=#host-element0 title="host element">host element</a>.
So, to allow this situation but prevent accidental styling,
the <a data-link-type=dfn href=#host-element0 title="host element">host element</a> appears but is completely featureless
and unselectable except through <a class=css data-link-type=maybe href=#selectordef-host0 title=:host>:host</a>.
</details>
<h3 class="heading settled heading" 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 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.
<h4 class="heading settled heading" 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-host0 title=:host>:host</a>, <a class=css data-link-type=maybe href=#selectordef-host title=:host()>:host()</a>, and <a class=css data-link-type=maybe href=#selectordef-host-context title=:host-context()>:host-context()</a> pseudo-classes</span><a class=self-link href=#host-selector></a></h4>
<p> The <dfn class=css-code data-dfn-type=selector data-export="" id=selectordef-host0>:host<a class=self-link href=#selectordef-host0></a></dfn> pseudo-class,
when evaluated in the context of a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>,
matches the <a data-link-type=dfn href=#shadow-tree title="shadow tree’s">shadow tree’s</a> <a data-link-type=dfn href=#host-element0 title="host element">host element</a>.
In any other context,
it matches nothing.
<p> The <dfn class=css-code data-dfn-type=selector data-export="" id=selectordef-host>:host()<a class=self-link href=#selectordef-host></a></dfn> function pseudo-class
has the syntax:
<pre>:host( <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-compound-selector title="<compound-selector>"><compound-selector></a> )</pre>
<p> When evaluated in the context of a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>,
it matches the <a data-link-type=dfn href=#shadow-tree title="shadow tree’s">shadow tree’s</a> <a data-link-type=dfn href=#host-element0 title="host element">host element</a>
if the <a data-link-type=dfn href=#host-element0 title="host element">host element</a>,
in its normal context,
matches the selector argument.
In any other context,
it matches nothing.
<div class=example>
For example, say you had a component with a <a data-link-type=dfn href=#shadow-tree title="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 title="shadow tree">shadow tree</a>:
<p> <ul>
<li><a class=css data-link-type=maybe href=#selectordef-host0 title=:host>:host</a> matches the <code><x-foo></code> element.
<li><span class=css data-link-type=maybe title=x-foo>x-foo</span> matches nothing.
<li><span class=css data-link-type=maybe title=.foo>.foo</span> matches only the <code><div></code> element.
<li><span class=css data-link-type=maybe title=.foo:host>.foo:host</span> matches nothing
<li><span class=css data-link-type=maybe title=:host(.foo)>:host(.foo)</span> matches the <code><x-foo></code> element.
</ul>
</div>
<p> Ordinary, selectors within a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>
can’t see elements outside the <a data-link-type=dfn href=#shadow-tree title="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.
<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-code 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 title="shadow tree">shadow tree</a>,
which matches a particular selector.
Its syntax is:
<pre>:host-context( <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-compound-selector title="<compound-selector>"><compound-selector></a> )</pre>
<p> When evaluated in the context of a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>,
the <a class=css data-link-type=maybe href=#selectordef-host-context title=:host-context()>:host-context()</a> pseudo-class matches the <a data-link-type=dfn href=#host-element0 title="host element">host element</a>,
if the <a data-link-type=dfn href=#host-element0 title="host element">host element</a> or one of its ancestors matches the provided <a class="production css-code" data-link-type=type href=http://dev.w3.org/csswg/selectors-4/#typedef-compound-selector title="<compound-selector>"><compound-selector></a>.
For the purpose of this pseudo-class,
the "ancestor" of an element is:
<dl>
<dt>if the element is distributed to a <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a>
<dd>
the <a data-link-type=element title=content>content</a> element it is ultimately distributed to.
<dt>if the element is a top-most element in a shadow tree
<dd>
the <a data-link-type=dfn href=#host-element0 title="host element">host element</a>
<dt>otherwise
<dd>
the element’s parent,
if it has one.
</dl>
<p class=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.
<h4 class="heading settled heading" 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 title=::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 title="shadow tree">shadow tree</a>,
the <dfn class=css-code 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 title="shadow roots">shadow roots</a> themselves.
In HTML, the <a data-link-type=dfn href=#shadow-root title="shadow root">shadow root</a> is represented by <a class=idl-code data-link-type=interface title=shadowroot>ShadowRoot</a> objects.
<p> The <a class=css data-link-type=maybe href=#selectordef-shadow title=::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 title=::shadow>::shadow</a> pseudo-element is considered to be the root of the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>,
with the <a data-link-type=dfn href=#top-level-element title="top-level elements">top-level elements</a> in the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> the direct children of the <a class=css data-link-type=maybe href=#selectordef-shadow title=::shadow>::shadow</a> pseudo-element.
<div class=example>
For example, say you had a component with a <a data-link-type=dfn href=#shadow-tree title="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 data-link-type=maybe title="x-foo::shadow > span">x-foo::shadow > span</span> matches <span class=css data-link-type=maybe title=#top>#top</span>,
but not <span class=css data-link-type=maybe title=#not-top>#not-top</span>,
because it’s not a <a data-link-type=dfn href=#top-level-element title="top-level element">top-level element</a> in the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>.
<p> If one wanted to target <span class=css data-link-type=maybe title=#not-top>#not-top</span>,
one way to do it would be with <span class=css data-link-type=maybe title="x-foo::shadow > div > span">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 data-link-type=maybe title="x-foo::shadow span">x-foo::shadow span</span>,
to select all the elements of some type in the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>.
</div>
<div class=example>
If an element has multiple <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a>,
a <a class=css data-link-type=maybe href=#selectordef-shadow title=::shadow>::shadow</a> pseudo-element selects <em>all</em> of the corresponding <a data-link-type=dfn href=#shadow-root title="shadow roots">shadow roots</a>.
<p> Similarly,
inside of a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>,
a selector like <span class=css data-link-type=maybe title=":host::shadow div">:host::shadow div</span> selects the <a data-link-type=element href=http://www.w3.org/html/wg/drafts/html/CR/grouping-content.html#the-div-element title=div>div</a> elements in <em>all</em> the <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a> on the element,
not just the one containing that selector.
</div>
<h4 class="heading settled heading" 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 title=::content>::content</a> pseudo-element</span><a class=self-link href=#content-combinator></a></h4>
<p> The <dfn class=css-code data-dfn-type=selector data-export="" id=selectordef-content>::content<a class=self-link href=#selectordef-content></a></dfn> pseudo-element matches the <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a> itself,
on elements that have one.
<p class=issue id=issue-1b6118ae><a class=self-link href=#issue-1b6118ae></a>
<a class=css data-link-type=maybe href=#selectordef-content title=::content>::content</a> is a confusingly general name for something that is specific
to the projected content of a shadow tree.
<p> The <a class=css data-link-type=maybe href=#selectordef-content title=::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 title=::content>::content</a> pseudo-element is considered to be the parent of the elements in the <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a>.
<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 title="shadow tree">shadow tree</a>,
a selector like <span class=css data-link-type=maybe title="::content div">::content div</span>
selects <span class=css data-link-type=maybe title=#one>#one</span>, <span class=css data-link-type=maybe title=#three>#three</span>, and <span class=css data-link-type=maybe title=#four>#four</span>,
as they’re the elements distributed by the sole <a data-link-type=element title=content>content</a> element,
but not <span class=css data-link-type=maybe title=#two>#two</span>.
<p> If only the <a data-link-type=dfn href=#top-level-element title="top-level elements">top-level elements</a> distributed the <a data-link-type=element title=content>content</a> element are desired,
a <a data-link-type=dfn href=http://dev.w3.org/csswg/selectors-4/#child-combinator title="child combinator">child combinator</a> can be used,
like <span class=css data-link-type=maybe title="::content > div">::content > div</span>,
which will exclude <span class=css data-link-type=maybe title=#four>#four</span>
as it’s not treated as a child of the <a class=css data-link-type=maybe href=#selectordef-content title=::content>::content</a> pseudo-element.
<p class=note> Note: Note that a selector like <span class=css data-link-type=maybe title="::content div">::content div</span>
is equivalent to <span class=css data-link-type=maybe title="*::content div">*::content div</span>,
where the <span class=css data-link-type=maybe title=*>*</span> selects many more elements that just the <a data-link-type=element title=content>content</a> element.
However, since only the <a data-link-type=element title=content>content</a> element has a <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a>,
it’s the only element that has a <a class=css data-link-type=maybe href=#selectordef-content title=::content>::content</a> pseudo-element as well.
</div>
<h4 class="heading settled heading" 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-deep title=/deep/>/deep/</a> combinator</span><a class=self-link href=#deep-combinator></a></h4>
<p> When a <dfn class=css-code data-dfn-type=selector data-export="" id=selectordef-deep>/deep/<a class=self-link href=#selectordef-deep></a></dfn> combinator 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 title="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.
<div class=example>
For example, say you had a component with a <a data-link-type=dfn href=#shadow-tree title="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 data-link-type=maybe title="x-foo /deep/ span">x-foo /deep/ span</span>
selects all three of <code><span></code> elements:
<span class=css data-link-type=maybe title=#top>#top</span>, <span class=css data-link-type=maybe title=#not-top>#not-top</span>, <em>and</em> <span class=css data-link-type=maybe title=#nested>#nested</span>.
</div>
<p class=issue id=issue-250ee37f><a class=self-link href=#issue-250ee37f></a>
This is basically a super-descendant combinator.
If the descendant combinator had a real glyph,
it would potentially be interesting to just double it.
Maybe we can give the descendant combinator a pseudonym of <span class=css data-link-type=maybe title=">>">>></span>,
as it itself is a super-child combinator?
Then <a class=css data-link-type=maybe href=#selectordef-deep title=/deep/>/deep/</a> could be spelled <span class=css data-link-type=maybe title=">>>">>>></span>
<h3 class="heading settled heading" 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 heading" 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=#css3cascade title=css3cascade>[CSS3CASCADE]</a>
<p> An additional cascade criteria must be added,
between Origin and Scope,
called Shadow Tree.
<p> <ul>
<li>
When comparing two declarations,
if one of them is in a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>
and the other is in a document that contains that <a data-link-type=dfn href=#shadow-tree title="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 title="shadow tree">shadow tree</a> wins.
<p class=note> Note: This is the <em>opposite</em> of how scoped styles work.
<li>
When comparing two declarations,
if both are in <a data-link-type=dfn href=#shadow-tree title="shadow trees">shadow trees</a> with the same <a data-link-type=dfn href=#host-element0 title="host element">host element</a>,
then for normal rules the declaration from the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> that was created most recently wins,
and for important rules the declaration from the <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a> that was created less recently wins.
</ul>
<p> When calculating <a href=http://dev.w3.org/csswg/css-cascade/#cascade-order>Order of Appearance</a>,
the tree of trees,
defined by the Shadow DOM specification,
is used to calculate ordering.
<h4 class="heading settled heading" data-level=3.3.2 id=inheritance><span class=secno>3.3.2 </span><span class=content>
Inheritance</span><a class=self-link href=#inheritance></a></h4>
<p> The <a data-link-type=dfn href=#top-level-element title="top-level elements">top-level elements</a> of a <a data-link-type=dfn href=#shadow-tree title="shadow tree">shadow tree</a>
inherit from their <a data-link-type=dfn href=#host-element0 title="host element">host element</a>.
<p> The elements in a <a data-link-type=dfn href=#distribution-list title="distribution list">distribution list</a> inherit from the parent of the <a data-link-type=element title=content>content</a> element they are ultimately distributed to,
rather than from their normal parent.
<h2 class="heading settled heading" data-level=4 id=fragment-scoping><span class=secno>4 </span><span class=content>
Fragmented Styling</span><a class=self-link href=#fragment-scoping></a></h2>
<p> Fragmented content can be styled differently
based on which line, column, page, region, etc.
it appears in.
This is done by using an appropriate <dfn data-dfn-type=dfn data-export="" id=fragment-pseudo-element>fragment pseudo-element<a class=self-link href=#fragment-pseudo-element></a></dfn>,
which allows targetting individual fragments of an element
rather than the entire element.
<div class=example>
In our example,
the designer wants to make
text flowing into #region1
dark blue and bold.
This design can be expressed as shown below.
<pre>#region1::region p {
color: #0C3D5F;
font-weight: bold;
}
</pre>
<p> The <span class=css data-link-type=maybe title=::region>::region</span> pseudo-element
is followed by a <span class=css data-link-type=maybe title=p>p</span> relative selector in this example.
The color and font-weight declarations will apply
to any fragments of paragraphs that are
displayed in <span class=css data-link-type=maybe title=#region1>#region1</span>.
The following figure shows how
the rendering changes
if we apply this styling specific to <span class=css data-link-type=maybe title=#region1>#region1</span>.
Note how less text fits into this box
now that the <a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-fonts-3/#propdef-font-weight title=font-weight>font-weight</a> is
bold instead of normal.</p>
<figure>
<img alt="Illustrate how changing region styling affects the flow of content." src=images/region-styling.png width=450>
<figcaption>Different rendering with a different region styling</figcaption>
</figure>
</div>
<p class=note> Note: This feature is an extension of <span class=css data-link-type=maybe title=::first-line>::first-line</span> styling.
<h3 class="heading settled heading" data-level=4.1 id=the-region-pseudo-element><span class=secno>4.1 </span><span class=content>
Region-based Styling: the <span class=css data-link-type=maybe title=::region>::region</span> pseudo-element</span><a class=self-link href=#the-region-pseudo-element></a></h3>
<div class=issue id=issue-f778a2c0><a class=self-link href=#issue-f778a2c0></a>
Extend this to specify:
<ul>
<li><span class=css data-link-type=maybe title="<region-element-selector>::region"><region-element-selector>::region</span>
<li><span class=css data-link-type=maybe title="<paginated-element-selector>::page(<page-selector>)"><paginated-element-selector>::page(<page-selector>)</span>
<li><span class=css data-link-type=maybe title="<multicol-element>::column(<anb>)"><multicol-element>::column(<AnB>)</span>
<li><span class=css data-link-type=maybe title="<fragmented-element-selector>::nth-fragment(<anb>)"><fragmented-element-selector>::nth-fragment(<AnB>)</span>
<li><span class=css data-link-type=maybe title=::first-line>::first-line</span>
</ul>
</div>
<p>A ::region pseudo-element represents a relationship between
a selector that matches a <span>CSS Region</span>,
and a relative selector that matches some named flow content.
This allows style declarations to be applied
to fragments of named flow content flowing
into particular regions.</p>
<pre><region selector>::region <content selector> {
... CSS styling declarations ...
}
</pre>
<p>When the ::region pseudo-element is appended to a
<a href=http://www.w3.org/TR/css3-selectors/#selector-syntax>selector</a>
that matches one or more <span title="CSS Region">CSS Regions</span>,
this creates a 'flow fragment' selector.
The flow fragment selector specifies
which range of elements in the flow
can be matched by the relative selector.
The relative selector can match elements
in the range(s) (see <a data-biblio-type=normative data-link-type=biblio href=#dom title=dom>[DOM]</a>) of the named flow
that are displayed fully or partially
in the selected region(s).</p>
<p>Elements that are fully or partially
in the flow fragment range may match the relative selector.
However, the style declarations only apply
to the fragment of the element
that is displayed in the corresponding region(s).</p>
<p>Only a limited list of properties apply to a ::region pseudo-element:</p>
<p class=issue id=issue-9b00b7af><a class=self-link href=#issue-9b00b7af></a>
Either this list should be all functionally inheritable properties,
or all properties.
Why is it a seemingly-arbitrary subset of all properties, including box properties?
<ol>
<li><a href=http://www.w3.org/TR/CSS2/fonts.html>font properties</a></li>
<li><a href=http://www.w3.org/TR/CSS2/colors.html>color property</a></li>
<li><a href=http://www.w3.org/TR/css3-color/#transparency>opacity property</a></li>
<li><a href=http://www.w3.org/TR/css3-background/#backgrounds>background property</a></li>
<li><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-text-3/#word-spacing title=word-spacing>word-spacing</a></li>
<li><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-text-3/#letter-spacing title=letter-spacing>letter-spacing</a></li>
<li><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-text-decor-3/#text-decoration title=text-decoration>text-decoration</a></li>
<li><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-text-3/#text-transform title=text-transform>text-transform</a></li>
<li><a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visudet.html#propdef-line-height title=line-height>line-height</a></li>
<li><a href=http://www.w3.org/TR/css3-text/#justification>alignment and justification properties</a></li>
<li><a href=http://www.w3.org/TR/css3-background/#borders>border properties</a></li>
<li><a href=http://www.w3.org/TR/css3-background/#corners>rounded corner properties</a></li>
<li><a href=http://www.w3.org/TR/css3-background/#border-images>border images properties</a></li>
<li><a href=http://www.w3.org/TR/CSS2/box.html#margin-properties>margin properties</a></li>
<li><a href=http://www.w3.org/TR/CSS2/box.html#padding-properties>padding properties</a></li>
<li><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-text-decor-3/#text-shadow title=text-shadow>text-shadow</a></li>
<li><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-backgrounds-3/#box-shadow title=box-shadow>box-shadow</a></li>
<li><a class=property data-link-type=propdesc href=http://dev.w3.org/csswg/css-break-3/#box-decoration-break title=box-decoration-break>box-decoration-break</a></li>
<li><a class=property data-link-type=propdesc href=http://www.w3.org/TR/CSS21/visudet.html#propdef-width title=width>width</a></li>
</ol>
<div class=example id=region-style-example><a class=self-link href=#region-style-example></a>
<p>In the following example, the <span>named flow</span> “article-flow” flows
into “region-1” and “region-2”.</p>
<pre><style>
#div-1 {
<strong>flow-into: article-flow;</strong>
}
#region-1, #region-2 {
<strong>flow-from: article-flow;</strong>
}
/* region styling */
<strong>#region-1::region p </strong> {
margin-right: 5em;
}
</style>
<body>
<div id="div-1">
<p id="p-1">...</p>
<p id="p-2">...</p>
</div>
<div id="region-1"></div>
<div id="region-2"></div>
</body>
</pre>
<div id=region_styling_illustration>
<img alt="Example showing how a named flow content fits into regions to illustrate region styling." id=region_styling_img_2 src=images/region-styling-2.png>
<p> <ul class=swatch-list>
<li><span class=swatch style=background:#1C75BC> </span>div div-1</li>
<li><span class=swatch style=background:crimson> </span>paragraph p-1</li>
<li><span class=swatch style=background:white> </span>paragraph p-2</li>
<li><span class=swatch style=background:#E6E7E8> </span>range of flow that fits into
region-1</li>
<li><span class=swatch style=background:#BCBEC0> </span>range of flow that fits into
region-2</li>
</ul>
</div>
<p>The region styling applies
to flow content that fits in <span class=css data-link-type=maybe title=region-1>region-1</span>.
The relative selector matches <span class=css data-link-type=maybe title=p-1>p-1</span> and <span class=css data-link-type=maybe title=p-2>p-2</span>
because these paragraphs
flow into <span class=css data-link-type=maybe title=region-1>region-1</span>.
Only the fragment of <span class=css data-link-type=maybe title=p-2>p-2</span>
that flows into <span class=css data-link-type=maybe title=region-1>region-1</span>
is styled with the pseudo-element.</p>
</div>
<p>All of the selectors
in a ::region pseudo-element
contribute to its <a href=http://www.w3.org/TR/css3-selectors/#specificity>specificity</a>.
So the specificity of the ::region pseudo-element
in the example above would combine
the id selector’s specificity
with the specificity of the type selector,
resulting in a specificity of 101.</p>
<p>Selectors that match a given element or element fragment (as described above),
participate in the <a href=http://www.w3.org/TR/2011/REC-CSS2-20110607/cascade.html#cascading-order>CSS Cascading
order</a> as defined in <a data-biblio-type=normative data-link-type=biblio href=#css21 title=css21>[CSS21]</a>.</p>
<div>
Region styling does not apply to nested regions. For example, if a region
<span class=css data-link-type=maybe title=a>A</span> receives content from a flow that contains region <span class=css data-link-type=maybe title=b>B</span>, the content that
flows into <span class=css data-link-type=maybe title=b>B</span> does not receive the region styling specified for region <span class=css data-link-type=maybe title=a>A</span>.
</div>
<p class=issue id=issue-5bff6297><a class=self-link href=#issue-5bff6297></a>
We’ll need some way to query the styles of a fragment in a particular region.
<code>getComputedStyle()</code> isn’t enough,
because an element can exist in multiple regions, for example,
with each fragment receiving different styles.
<h2 class="no-ref no-num heading settled heading" id=conformance><span class=content>
Conformance</span><a class=self-link href=#conformance></a></h2>
<h3 class="no-ref heading settled heading" id=conventions><span class=content>
Document conventions</span><a class=self-link href=#conventions></a></h3>
<p>Conformance requirements are expressed with a combination of
descriptive assertions and RFC 2119 terminology. The key words "MUST",
"MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT",
"RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this
document are to be interpreted as described in RFC 2119.
However, for readability, these words do not appear in all uppercase
letters in this specification.
<p>All of the text of this specification is normative except sections
explicitly marked as non-normative, examples, and notes. <a data-biblio-type=normative data-link-type=biblio href=#rfc2119 title=rfc2119>[RFC2119]</a></p>
<p>Examples in this specification are introduced with the words "for example"
or are set apart from the normative text with <code>class="example"</code>,
like this:
<div class=example>
<p>This is an example of an informative example.</p>
</div>
<p>Informative notes begin with the word "Note" and are set apart from the
normative text with <code>class="note"</code>, like this:
<p class=note>Note, this is an informative note.</p>
<h3 class="no-ref heading settled heading" id=conformance-classes><span class=content>
Conformance classes</span><a class=self-link href=#conformance-classes></a></h3>
<p>Conformance to this specification
is defined for three conformance classes:
<dl>
<dt>style sheet
<dd>A <a href=http://www.w3.org/TR/CSS21/conform.html#style-sheet>CSS
style sheet</a>.
<dt>renderer
<dd>A <a href=http://www.w3.org/TR/CSS21/conform.html#user-agent>UA</a>
that interprets the semantics of a style sheet and renders
documents that use them.
<dt>authoring tool
<dd>A <a href=http://www.w3.org/TR/CSS21/conform.html#user-agent>UA</a>
that writes a style sheet.
</dl>
<p>A style sheet is conformant to this specification
if all of its statements that use syntax defined in this module are valid
according to the generic CSS grammar and the individual grammars of each
feature defined in this module.
<p>A renderer is conformant to this specification
if, in addition to interpreting the style sheet as defined by the
appropriate specifications, it supports all the features defined
by this specification by parsing them correctly
and rendering the document accordingly. However, the inability of a
UA to correctly render a document due to limitations of the device
does not make the UA non-conformant. (For example, a UA is not
required to render color on a monochrome monitor.)
<p>An authoring tool is conformant to this specification
if it writes style sheets that are syntactically correct according to the
generic CSS grammar and the individual grammars of each feature in
this module, and meet all other conformance requirements of style sheets
as described in this module.
<h3 class="no-ref heading settled heading" id=partial><span class=content>
Partial implementations</span><a class=self-link href=#partial></a></h3>
<p>So that authors can exploit the forward-compatible parsing rules to
assign fallback values, CSS renderers <strong>must</strong>
treat as invalid (and <a href=http://www.w3.org/TR/CSS21/conform.html#ignore>ignore
as appropriate</a>) any at-rules, properties, property values, keywords,
and other syntactic constructs for which they have no usable level of
support. In particular, user agents <strong>must not</strong> selectively
ignore unsupported component values and honor supported values in a single
multi-value property declaration: if any value is considered invalid
(as unsupported values must be), CSS requires that the entire declaration
be ignored.</p>
<h3 class="no-ref heading settled heading" id=experimental><span class=content>
Experimental implementations</span><a class=self-link href=#experimental></a></h3>
<p>To avoid clashes with future CSS features, the CSS2.1 specification
reserves a <a href=http://www.w3.org/TR/CSS21/syndata.html#vendor-keywords>prefixed
syntax</a> for proprietary and experimental extensions to CSS.