-
Notifications
You must be signed in to change notification settings - Fork 708
/
Copy pathOverview.bs
810 lines (677 loc) · 33.3 KB
/
Overview.bs
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
<pre class=metadata>
Title: CSS Containment Module Level 1
Level: 1
Shortname: css-contain
Status: ED
Work Status: Testing
Group: csswg
ED: https://drafts.csswg.org/css-contain/
TR: https://www.w3.org/TR/css-contain-1/
Previous Version: https://www.w3.org/TR/2018/CR-css-contain-1-20180524/
Previous Version: https://www.w3.org/TR/2017/CR-css-contain-1-20170808/
Previous Version: https://www.w3.org/TR/2017/WD-css-contain-1-20170419/
Previous Version: https://www.w3.org/TR/2017/WD-css-contain-1-20170221/
Editor: Tab Atkins, Google, http://xanthir.com/contact/, w3cid 42199
Editor: Florian Rivoal, On behalf of Bloomberg, https://florian.rivoal.net/, w3cid 43241
Abstract: This CSS module describes the 'contain' property, which indicates that the element's subtree is independent of the rest of the page. This enables heavy optimizations by user agents when used well.
Ignored Terms: scrollWidth, scrollHeight, clientWidth, clientHeight
WPT Path Prefix: css/css-contain/
</pre>
<pre class="anchors">
spec: css2; urlPrefix: https://www.w3.org/TR/CSS2/
type: property; url: generate.html#propdef-content; text: content
type: property; url: visudet.html#propdef-vertical-align; text: vertical-align
type: value; for: content; url: generate.html#value-def-open-quote; text: open-quote
type: value; for: content; url: generate.html#value-def-close-quote; text: close-quote
type: value; for: content; url: generate.html#value-def-no-open-quote; text: no-open-quote
type: value; for: content; url: generate.html#value-def-no-close-quote; text: no-close-quote
type: dfn; url: box.html#padding-edge; text: padding edge
spec: css-backgrounds-3;
type: dfn; url: https://drafts.csswg.org/css-backgrounds-3/#corner-clipping; text: corner clipping
</pre>
<pre class=link-defaults>
spec:css2; type:dfn; text:stacking context
spec:css2; type:property; text:content
spec:css-display-3; type:property; text:display
spec:css2; type:property; text:counter-increment
spec:css-ui-3; type:property; text:text-overflow
spec:css-grid-1; type:property; text:grid
</pre>
<h2 id='intro'>
Introduction</h2>
Efficiently rendering a website relies on the User Agent being able to detect what parts of the page are being displayed,
which parts might affect the currently-displayed section,
and what can be ignored.
There are various heuristics that can be used to guess when a given sub-tree is independent of the rest of the page in some manner,
but they're fragile,
so innocuous changes to a page may inadvertently make it flunk the heuristics and fall into a slow mode.
There are also many things that would be good to isolate which are difficult or impossible to detect in a heuristic manner.
To alleviate these problems
and allow strong, predictable isolation of a subtree from the rest of the page,
this specification defines a 'contain' property.
<h2 id='contain-property'>
Strong Containment: the 'contain' property</h2>
<pre class='propdef'>
Name: contain
Value: none | strict | content | [ size || layout || style || paint ]
Initial: none
Inherited: no
Applies to: See <a href="#contain-applies">below</a>
Computed value: specified keyword(s)
Animation type: not animatable
</pre>
<wpt>
contain-animation-001.html
inheritance.html
</wpt>
<p class=all-media>User Agents are expected to support this property on all media, including non-visual ones.</p>
The 'contain' property allows an author to indicate that an element and its contents are,
as much as possible,
<em>independent</em> of the rest of the document tree.
This allows user agents to utilize much stronger optimizations when rendering a page using 'contain' properly,
and allows authors to be confident that their page won't accidentally fall into a slow code path
due to an innocuous change.
<dl dfn-type=value dfn-for=contain>
<dt><dfn>none</dfn>
<dd>
This value indicates that the property has no effect.
The element renders as normal,
with no containment effects applied.
<dt><dfn>strict</dfn>
<dd>
This value turns on all forms of <a>containment</a> for the element.
In other words, it behaves the same as ''contain: size layout style paint;'',
so that its contents are guaranteed to have no effect on the rest of the page outside the element's bounds.
<dt><dfn>content</dfn>
<dd>
This value turns on all forms of <a>containment</a> <em>except</em> <a>size containment</a> for the element.
In other words, it behaves the same as ''contain: layout style paint;''.
Note: ''contain: content'' is reasonably "safe" to apply widely;
its effects are fairly minor in practice,
and most content won't run afoul of its restrictions.
However, because it doesn't apply <a>size containment</a>,
the element can still respond to the size of its contents,
which can cause layout-invalidation to percolate further up the tree than desired.
Use ''contain: strict'' when possible,
to gain as much containment as you can.
<dt><dfn>size</dfn>
<dd>
The value turns on <a>size containment</a> for the element.
This ensures that the containing element can be laid out
without needing to examine its descendants.
<dt><dfn>layout</dfn>
<dd>
This value turns on <a>layout containment</a> for the element.
This ensures that the containing element is <em>totally opaque</em> for layout purposes;
nothing outside can affect its internal layout,
and vice versa.
<dt><dfn>style</dfn>
<dd>
This value turns on <a>style containment</a> for the element.
This ensures that,
for properties which can have effects on more than just an element and its descendants,
those effects don't escape the containing element.
<dt><dfn>paint</dfn>
<dd>
This value turns on <a>paint containment</a> for the element.
This ensures that the descendants of the containing element don't display outside its bounds,
so if an element is off-screen or otherwise not visible,
its descendants are also guaranteed to be not visible.
</dl>
<wpt>
contain-layout-size-003.html
contain-paint-size-001.html
contain-paint-size-002.html
contain-paint-size-003.html
contain-strict-001.html
contain-strict-002.html
contain-strict-003.html
</wpt>
<span id="contain-applies">This property generally applies to all elements (including [[css-pseudo-4#generated-content]])</span>,
although some types of containment have no effect on some elements,
as detailed in [[#containment-types]].
In addition, in the case of [[SVG2]],
the 'contain' property only applies to <{svg}> elements that have an associated CSS layout box.
<div class='example'>
'contain' is useful when used widely on a page,
particularly when a page contains a lot of "widgets" which are all independent.
For example, assume a micropost social network had markup something like this:
<pre><code highlight=markup>
<body>
<aside>...</aside>
<section>
<h2>Messages</h2>
<article>
Lol, check out this dog: images.example.com/jsK3jkl
</article>
<article>
I had a ham sandwich today. #goodtimes
</article>
<article>
I have political opinions that you need to hear!
</article>
…
</section>
</body>
</code></pre>
There are probably a <em>lot</em> of messages displayed on the site,
but each is independent and won't affect anything else on the site.
As such, each can be marked with ''contain: content'' to communicate this to the user agent,
so it can optimize the page and skip a lot of computation for messages that are off-screen.
If the size of each message is known ahead of time,
''contain: strict'' can be applied to communicate further restrictions.
</div>
<h2 id='containment-types'>
Types of Containment</h2>
There are several varieties of <dfn export>containment</dfn> that an element can be subject to,
restricting the effects that its descendants can have on the rest of the page in various ways.
<a>Containment</a> enables much more powerful optimizations by user agents,
and helps authors compose their page out of functional units,
as it limits how widely a given change can affect a document.
Advisement: Specification authors introducing new properties or mechanisms
need to consider whether and how the various types of containment
affect what they are introducing,
and include in their specification any effect not described here.
<h3 id='containment-size'>
Size Containment</h3>
If the element does not generate a <a>principal box</a> (as is the case with ''display: contents'' or ''display: none''),
or if the element is a ''display/table'',
or if the element is an <a spec="css-display-3">internal table element</a>,
or if the element is an <a spec="css-display-3">internal ruby element</a>,
or if the element's <a>principal box</a> is a <a spec="css-display-3" lt="atomic inline">non-atomic</a> <a spec="css-display-3">inline-level</a> box,
size containment has no effect.
Otherwise, giving an element <dfn export>size containment</dfn> has the following effects:
<wpt>
contain-size-001.html
contain-size-002.html
contain-size-003.html
contain-size-004.html
contain-size-005.html
contain-size-006.html
contain-size-007.html
contain-size-008.html
contain-size-009.html
contain-size-010.html
contain-size-012.html
contain-size-051.html
contain-size-052.html
</wpt>
Note: Internal table elements,
which do not include table captions,
are excluded,
because the table layout algorithm
does not allow elements to become smaller than their inflow content.
Sizing a table cell as if it was empty and then layout out its content inside without changing the size
is effectively an undefined operation.
Manually setting the 'width' or 'height' properties to ''0''
cannot make it smaller than its content.
This concern does not apply to table captions,
which are perfectly capable of having a fixed size
that is independent of their content.
<wpt>
contain-size-011.html
contain-size-056.html
</wpt>
1. When calculating the size of the containing element,
it must be treated as having no contents.
<wpt>
contain-size-021.html
contain-size-023.html
contain-size-025.html
contain-size-027.html
contain-size-061.html
contain-size-062.html
contain-size-borders.html
contain-size-fieldset-001.html
contain-size-scrollbars-001.html
contain-size-button-001.html
contain-size-flexbox-001.html
contain-size-grid-001.html
</wpt>
Note: Even when the element's [=sizing properties=] are ''height/auto''
this does not necessarily make the element zero-sized:
properties set on the element itself,
such as the 'columns' property or the 'grid' property,
continue to be taken into account.
<wpt>
contain-size-grid-002.html
contain-size-multicol-001.html
</wpt>
Then,
its contents must then be laid out into the containing element's resolved size.
Note: [=size containment=] does not suppress baseline alignment.
See [=layout containment=] for that.
<wpt>
contain-size-baseline-001.html
</wpt>
<a>Replaced elements</a> must be treated as having an intrinsic width and height of 0.
<wpt>
contain-size-013.html
contain-size-041.html
contain-size-042.html
</wpt>
2. Elements with <a>size containment</a> are <a spec=css-break-3>monolithic</a> (See [[CSS-BREAK-3#possible-breaks]]).
<wpt>
contain-size-breaks-001.html
contain-size-monolithic-001.html
</wpt>
By itself, <a>size containment</a> does not offer much optimization opportunity.
Its primary benefit on its own is that tools which want to lay out the containing element's contents
based on the containing element's size
(such as a JS library implementing the "container query" concept)
can do so without fear of "infinite loops",
where having a child's size respond to the size of the containing element
causes the containing element's size to change as well,
possibly triggering <em>further</em> changes in how the child sizes itself
and possibly thus more changes to the containing element's size,
ad infinitum.
When paired with <a>layout containment</a>, though,
possible optimizations that can be enabled include (but are not limited to):
1. When the style or contents of a descendant of the containing element is changed,
calculating what part of the DOM tree is "dirtied" and might need to be re-laid out
can stop at the containing element.
2. When laying out the page,
if the containing element is off-screen or obscured,
the layout of its contents can be delayed or done at a lower priority.
<h3 id='containment-layout'>
Layout Containment</h3>
If the element does not generate a <a>principal box</a> (as is the case with ''display: contents'' or ''display: none''),
or if the element is an <a spec="css-display-3">internal table element</a> other than ''display: table-cell'',
or if the element is an <a spec="css-display-3">internal ruby element</a>,
or if the element's <a>principal box</a> is a <a spec="css-display-3" lt="atomic inline">non-atomic</a> <a spec="css-display-3">inline-level</a> box,
layout containment has no effect.
Otherwise, giving an element <dfn export>layout containment</dfn> has the following effects:
<wpt>
contain-layout-001.html
contain-layout-002.html
contain-layout-003.html
contain-layout-004.html
contain-layout-005.html
contain-layout-009.html
contain-layout-010.html
contain-layout-011.html
contain-layout-012.html
contain-layout-013.html
contain-layout-014.html
contain-layout-independent-formatting-context-003.html
</wpt>
1. The element [=establishes an independent formatting context=].
<wpt>
contain-layout-ifc-022.html
contain-layout-independent-formatting-context-001.html
contain-layout-independent-formatting-context-002.html
</wpt>
2. If at least one [=fragmentation container=] of a [=fragmentation context=] has [=layout containment=],
or if at least one [=fragmentation container=] of a [=fragmentation context=] is a descendant of an element with layout containment
<strong>and</strong> at least one subsequent [=fragmentation container=] of the same [=fragmentation context=]
is not a descendant of that same element with layout containment,
then the first element with [=layout containment=]
which is either a [=fragmentation container=] itself
or is an ancestor of a [=fragmentation container=]
must “trap” the remainder of the [=fragmented flow=]:
[=fragmentation=] must not continue past the [=layout containment=] boundary,
and the last [=fragmentation container=]
within the first [=layout containment=] boundary
is treated as if it is the last [=fragmentation container=]
in its [=fragmentation context=].
If subsequent [=fragmentation containers=] in the [=fragmentation context=]
are only generated when more content remains in the [=fragmented flow=],
then they are not generated.
If they would exist regardless,
they remain part of the [=fragmentation context=],
but do not receive any content from the [=fragmented flow=].
Note: At the time of writing, no stable specification is affected by this point.
Only specifications that would enable some (but not all) fragmentation containers of a fragmentation context
to be layout-contained (or descendants of a layout contained element)
are concerned.
This is not the case of [[CSS-PAGE-3]] nor of [[CSS-MULTICOL-1]].
This requirement is nonetheless included because
several mechanisms that would make this a possibility have been considered
(e.g.: [[CSS-REGIONS-1]], ''::nth-fragment()'', a hypothetical selector for individual columns of a multicol…),
and the guarantees that layout containment is intended to offer would not be realized
if such mechanisms did not abide by this rule.
[[CSS-REGIONS-1]] has details over how <a>layout containment</a> affects
regions.
<div class=example>
<pre><code highlight=markup>
<article>Lorem ipsum…</article>
<div id=a></div>
<aside>
<div id=b></div>
<div id=c></div>
</aside>
<aside>
<div id=d></div>
<div id=e></div>
</aside>
<div id=f></div>
</code></pre>
<pre><code highlight=css>
article {flow-into: foo;}
#a, #b, #c, #d, #e, #f {flow-from: foo;}
aside {contain: layout}
</code></pre>
In this [[CSS-REGIONS-1]] example,
content can flow from <code>#a</code> to <code>#b</code>,
from <code>#b</code> to <code>#c</code>.
However as <code>#c</code> is the last fragment container in the first layout-contained element,
it traps all the remaining content,
and nothing gets flowed into <code>#d</code>, <code>#e</code>, or <code>#f</code>.
</div>
3. If the computed value of the 'overflow' property is
either ''overflow/visible'' or ''overflow/clip'' or a combination thereof,
any overflow must be treated as [=ink overflow=].
<wpt>
contain-layout-ink-overflow-013.html
contain-layout-ink-overflow-014.html
contain-layout-ink-overflow-015.html
contain-layout-ink-overflow-016.html
contain-layout-ink-overflow-017.html
contain-layout-ink-overflow-018.html
contain-layout-ink-overflow-019.html
contain-layout-ink-overflow-020.html
</wpt>
4. The element acts as a containing block for absolutely positioned and fixed positioned descendants.
<wpt>
contain-layout-006.html
contain-layout-007.html
contain-layout-cell-001.html
contain-layout-cell-002.html
</wpt>
5. The element creates a <a>stacking context</a>.
<wpt>
contain-layout-016.html
contain-layout-017.html
contain-layout-018.html
</wpt>
6. [=Forced breaks=] are allowed within elements with [=layout containment=],
but do not propagate to the parent as otherwise described in [[CSS-BREAK-3#break-between]].
<wpt>
contain-layout-breaks-001.html
contain-layout-breaks-002.html
</wpt>
Note: This introduces the previously non-existent possibility that [=forced breaks=]
may occur between a box and its container (See [[CSS-BREAK-3#possible-breaks]]).
7. For the purpose of the 'vertical-align' property,
or any other property whose effects
need to relate the position of the containing element's baseline
to something other than its descendants,
the containing element is treated as having no baseline.
<wpt>
contain-layout-baseline-001.html
contain-layout-button-001.html
contain-layout-flexbox-001.html
contain-layout-grid-001.html
</wpt>
Possible optimizations that can be enabled by <a>layout containment</a> include (but are not limited to):
1. When laying out the page,
the contents of separate containing elements
can be laid out in parallel,
as they're guaranteed not to affect each other.
2. When laying out the page,
if the containing element is off-screen or obscured
and the layout of the visible parts of the screen do not depend on the size of the containing element
(for example, if the containing element is near the end of a block container,
and you're viewing the beginning of the block container),
the layout of the containing elements' contents can be delayed or done at a lower priority.
(When paired with <a>size containment</a>,
this optimization can be applied more liberally.)
<h3 id='containment-style'>
Style Containment</h3>
Giving an element <dfn export>style containment</dfn> has the following effects:
1. The 'counter-increment' and 'counter-set' properties
must be <a for=property>scoped to the element's sub-tree</a>
and create a new counter.
<wpt>
contain-style-counters-001.html
contain-style-counters-002.html
contain-style-counters-003.html
contain-style-counters-004.html
</wpt>
2. The effects of the 'content' property's
''content/open-quote'', ''content/close-quote'', ''content/no-open-quote'' and ''content/no-close-quote''
must be <a for=property>scoped to the element's sub-tree</a>.
Note: This implies that the depth of quote nesting in the subtree
is unchanged and starts at the value that its context normally implies,
but that changes to the depth of quote nesting by these values inside the subtree
do not affect the depth of quote nesting outside the subtree.
<wpt>
quote-scoping-001.html
quote-scoping-002.html
quote-scoping-003.html
quote-scoping-004.html
</wpt>
<wpt>
contain-style-baseline-001.html
contain-style-breaks-001.html
contain-style-breaks-002.html
contain-style-breaks-003.html
contain-style-breaks-004.html
contain-style-breaks-005.html
</wpt>
Note: [[CSS-REGIONS-1]] has normative requirements on how <a>style containment</a> affects regions.
A <dfn export for=property lt="scoped | scoped property | scoped properties">scoped property</dfn> has its effects scoped to a particular element or subtree.
* If <dfn export for=property lt="scoped to an element | scoped to the element">scoped to an element</dfn>,
it must act as if the scoping element was the root of the document
for the purpose of evaluating the property's effects:
any uses of the property outside the scoping element must have no effect on the uses of the property on or in the scoping element,
and vice versa.
Note: “Scoping to an element” is currently unused.
It is defined as an extension point for future specifications to use.
* If <dfn export for=property lt="scoped to a sub-tree | scoped to the sub-tree | scoped to the element's sub-tree | scoped to an element's sub-tree">scoped to a sub-tree</dfn>, it's the same,
except the scoping element itself is counted as "outside" the tree,
like the rest of the document,
and the effects of the property on that element are unaffected by scoping.
When considering the effects of the scoped property on elements <em>inside</em> the subtree,
the element at the base of the subtree is treated as if it was the root of the document.
<wpt>
counter-scoping-001.html
counter-scoping-002.html
counter-scoping-003.html
</wpt>
<div class=example>
As 'counter-increment' is scoped to an element's subtree,
the first use of it within the subtree acts as if the named counter were set to 0 at the scoping element,
regardless of whether the counter had been used outside the scoping element.
Any increments made within the subtree have no effect on counters of the same name outside the scoping element.
However, the ''content/counter()'' and ''content/counters()'' value of the 'content' property is not itself scoped,
and can refer to counters established outside of the subtree.
Therefore, the following code results in <q><samp>1 1.2</samp></q> being displayed:
<pre><code highlight=markup>
<div></div>
</code></pre>
<pre><code highlight=css>
div {
contain: style;
counter-increment: n;
}
div::before, div::after {
content: counters(n, '.') " ";
}
div::after {
counter-increment: n 2;
}
</code></pre>
</div>
Possible optimizations that can be enabled by <a>style containment</a> include (but are not limited to):
1. Whenever a property is changed on a descendant of the containing element,
calculating what part of the DOM tree is "dirtied" and might need to have its style recalculated
can stop at the containing element.
<h3 id='containment-paint'>
Paint Containment</h3>
If the element does not generate a <a>principal box</a> (as is the case with ''display: contents'' or ''display: none''),
or if the element is an <a spec="css-display-3">internal table element</a> other than ''display: table-cell'',
or if the element is an <a spec="css-display-3">internal ruby element</a>,
or if the element's <a>principal box</a> is a <a spec="css-display-3" lt="atomic inline">non-atomic</a> <a spec="css-display-3">inline-level</a> box,
paint containment has no effect.
Otherwise, giving an element <dfn export>paint containment</dfn> has the following effects:
<wpt>
contain-paint-002.html
contain-paint-005.html
contain-paint-006.html
contain-paint-007.html
contain-paint-008.html
contain-paint-011.html
contain-paint-012.html
contain-paint-014.html
contain-paint-015.html
contain-paint-016.html
contain-paint-017.html
contain-paint-018.html
contain-paint-019.html
contain-paint-independent-formatting-context-003.html
</wpt>
1. The contents of the element
including both the paint of the descendants and their geometry
must be clipped to the <a>padding edge</a> of the element's <a>principal box</a>,
taking <a>corner clipping</a> into account.
This does not include the creation of any mechanism
to access or indicate the presence of the clipped content;
nor does it inhibit the creation of any such mechanism through other properties,
<span class=informative>such as 'overflow', 'resize', or 'text-overflow'</span>.
<span class=note>This is as if ''overflow: visible'' was changed to ''overflow: clip'' at used value.</span>
<wpt>
contain-paint-001.html
contain-paint-004.html
contain-paint-047.html
contain-paint-048.html
contain-paint-cell-001.html
contain-paint-cell-002.html
contain-paint-clip-011.html
contain-paint-clip-012.html
contain-paint-clip-013.html
contain-paint-clip-014.html
contain-paint-clip-015.html
contain-paint-clip-016.html
contain-paint-clip-017.html
contain-paint-clip-018.html
contain-paint-clip-019.html
</wpt>
2. The element acts as a containing block for absolutely positioned and fixed positioned descendants.
<wpt>
contain-paint-009.html
contain-paint-010.html
contain-paint-022.html
contain-paint-023.html
contain-paint-024.html
</wpt>
3. The element creates a <a>stacking context</a>.
<wpt>
contain-paint-020.html
contain-paint-021.html
contain-paint-025.html
</wpt>
4. The element [=establishes an independent formatting context=].
<wpt>
contain-paint-ifc-011.html
contain-paint-independent-formatting-context-001.html
contain-paint-independent-formatting-context-002.html
</wpt>
<wpt>
contain-paint-baseline-001.html
</wpt>
<div class=informative>
Possible optimizations that can be enabled by <a>paint containment</a> include (but are not limited to):
1. If the containing element is off-screen or obscured,
the UA can directly skip trying to paint its contents,
as they're guaranteed to be off-screen/obscured as well.
2. Unless the clipped content is made accessible via a separate mechanism
such as the 'overflow', 'resize', or 'text-overflow' properties,
the UA can reserve "canvas" space for the element exactly the element's size.
(In similar, scrollable, situations, like ''overflow: hidden'',
it's possible to scroll to the currently-clipped content,
so UAs often predictively overpaint somewhat
so there's something to see as soon as the scroll happens,
rather than a frame later.)
3. Because they are guaranteed to be stacking contexts,
scrolling elements can be painted into a single GPU layer.
</div>
Privacy and Security Considerations {#privsec}
==============================================
This specification introduces no new privacy or security considerations.
Like any other CSS specification, it affects the rendering of the document,
but does not introduce any special ability to present content in a misleading way
that was not previously available through other CSS modules
and that isn't inherent to the act of formatting the document.
The <a href="http://www.w3.org/2001/tag/">TAG</a> has developed a <a href="https://www.w3.org/TR/security-privacy-questionnaire/">self-review questionaire</a>
to help editors and Working Groups evaluate the risks introduced by their specifications.
Answers are provided below.
<dl>
<dt>Does this specification deal with personally-identifiable information?
<dd>No.
<dt>Does this specification deal with high-value data?
<dd>No.
<dt>Does this specification introduce new state for an origin that persists across browsing sessions?
<dd>No.
<dt>Does this specification expose persistent, cross-origin state to the web?
<dd>No.
<dt>Does this specification expose any other data to an origin that it doesn’t currently have access to?
<dd>No.
<dt>Does this specification enable new script execution/loading mechanisms?
<dd>No.
<dt>Does this specification allow an origin access to a user’s location?
<dd>No.
<dt>Does this specification allow an origin access to sensors on a user’s device?
<dd>No.
<dt>Does this specification allow an origin access to aspects of a user’s local computing environment?
<dd>No.
<dt>Does this specification allow an origin access to other devices?
<dd>No.
<dt>Does this specification allow an origin some measure of control over a user agent’s native UI?
<dd>No.
<dt>Does this specification expose temporary identifiers to the web?
<dd>No.
<dt>Does this specification distinguish between behavior in first-party and third-party contexts?
<dd>No.
<dt>How should this specification work in the context of a user agent’s "incognito" mode?
<dd>No difference in behavior is needed.
<dt>Does this specification persist data to a user’s local device?
<dd>No.
<dt>Does this specification have a "Security Considerations" and "Privacy Considerations" section?
<dd>Yes, this is the section you are currently reading.
<dt>Does this specification allow downgrading default security characteristics?
<dd>No.
</dl>
<h2 class="no-num non-normative" id="changes">Appendix A. Changes</h2>
This appendix is <em>informative</em>.
<h3 id="2018-05-24-changes">Changes from the
<a href="https://www.w3.org/TR/2018/CR-css-contain-1-20180524/">Candidate Recommendation of 24 May 2018</a></h3>
* Clarify that layout containment causes overflow to be treated as ink overflow only when visible (or clip)
* Layout containment suppresses baseline alignment, but size containment does not
* Layout containment causes the element to establish a new stacking context
* Size containment does not apply to tables
* Clarify that the columns and grid properties affect the size of size-contained elements
* Change the animation type of the contain property from discrete to not animatable
* Define the effect of containment on SVG elements
* Editorial improvements
* A comprehensive test suite for the full specification was developped, see <a href="http://test.csswg.org/harness/review/css-contain-1_dev">http://test.csswg.org/harness/review/css-contain-1_dev</a>
<h3 id="2017-08-08-changes">Changes from the
<a href="https://www.w3.org/TR/2017/CR-css-contain-1-20170808/">Candidate Recommendation of 8 August 2017</a></h3>
<ul>
<li>Clarify to which box paint containment clips (<a href="https://github.com/web-platform-tests/wpt/pull/10549/commits/5b92ee3c170e3be239937a3ae069f37655ff6671">see tests</a>).
<li>Move the interaction between containment and the <code>bookmark-*</code> and <code>string-set</code> properties to [[CSS-CONTENT-3]] (additional tests not needed, no change in behavior).
<li>Remove the effects of style containment on the "break-*" properties (<a href="https://github.com/web-platform-tests/wpt/pull/10549/commits/d6a4f606a0501fe6ca526483a7a379ba2e9eaa1c">see tests</a>).
<li>Move the description of the effects of containment on regions from this specification to [[CSS-REGIONS-1]] (additional tests not needed, no change in behavior).
<li>Clarify the effects of style scoping on counter-set and counter-increment (<a href="https://github.com/web-platform-tests/wpt/pull/10549/commits/d7fbc4794403dfeb55f13310d4c1cb51813e2d6e">see tests</a>)
<li>Size layout and paint containment don't apply to internal ruby elements (<a href="https://github.com/web-platform-tests/wpt/pull/10549/commits/ba5a04e3d65f9f39c2d6431a9ece5eb15d22116b">see tests</a>)
<li>Layout, Paint, and size containments do not apply to non-atomic inlines (see <a href="https://github.com/web-platform-tests/wpt/pull/10549/commits/402a19bde8981a402d9dba73083f84d96e4aeeb9">tests here</a> and <a href="https://github.com/web-platform-tests/wpt/pull/10549/commits/69b5681ee7aa5a028eb694b2c93bfd48c1ef08e4">one more test here</a>)
<li>Align paint containment's behavior with overflow:clip (<a href="https://github.com/web-platform-tests/wpt/pull/10549/commits/e2f844700a4a165f7ab6a0f021bbe1bf4d921cc0">see test</a>)
<li>Elements with size containment are monolithic (<a href="https://github.com/web-platform-tests/wpt/pull/10549/commits/536f74e4137196b34d63752f5a9217e23c4fb899#diff-bd8852c889db6d2b471bae58105f9374">see test</a>)
<li>Forced breaks area allowed in elements with layout containments, but do not propagate (<a href="https://github.com/web-platform-tests/wpt/pull/10549/commits/536f74e4137196b34d63752f5a9217e23c4fb899">see tests</a>)
<li>Clarify the effects of scoping to a subtree (<a href="https://github.com/web-platform-tests/wpt/pull/10549/commits/7aad64ade18bce9db257c34d72c6dad126a9e9cd">see test</a>)
<li>Clarify the effects of scoping on open/close quotes (<a href="https://github.com/web-platform-tests/wpt/pull/10549/commits/f6efd2ff775bea39e34b1b260959de618908046b">see tests</a>)
<li>Editorial clarification: replace "Becoming a formatting context" (aka "Becoming a formatting context root") with "Establish a FC" (additional tests not needed, no change in behavior)
</ul>
<h3 id="2017-04-19-changes">Changes from the
<a href="https://www.w3.org/TR/2017/WD-css-contain-1-20170419/">Working Draft of 19 April 2017</a></h3>
<ul>
<li>Clarify the interaction with display: contents
<li>Clarify how containment works on table parts
<li>Move the interaction between containment and fragmentation of overflow from this specification to CSS-OVERFLOW-4
</ul>
<h3 id="fpwd-changes">Changes from the
<a href="https://www.w3.org/TR/2017/WD-css-contain-1-20170221/">First Public Working Draft of 21 February 2017</a></h3>
<ul>
<li>Specify handling of replaced elements for size containment
<li>Layout containment makes element act as a containing block for absolutely positioned and fixed positioned descendants.
</ul>