forked from w3c/csswg-drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverview.bs
More file actions
1040 lines (872 loc) · 39 KB
/
Overview.bs
File metadata and controls
1040 lines (872 loc) · 39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<pre class='metadata'>
Title: CSS Scroll Snapping Change Proposal
Shortname: css-scroll-snap
Level: 1
Status: UD
Work Status: exploring
Group: CSSWG
ED: https://drafts.csswg.org/css-scroll-snap/
Editor: Tab Atkins-Bittner, Google, http://xanthir.com/contact/
Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact
Abstract: A brief description of an alternate model for scroll-snapping.
Ignored Terms: snap position, snap positions, inertial scroll, inertial scrolls, semantic scroll, semantic scrolls, scrollable area, scroll-group-align
</pre>
<pre class="link-defaults">
spec: css-shapes-1; type: value; for: <shape-box>
text: border-box
text: margin-box
spec: css-writing-modes-3; type: dfn
text: start
text: end
</pre>
Introduction {#intro}
=====================
We think scroll snapping is a great idea, and fully support exposing this functionality through CSS. However, a major weakness of the current spec is the way it conceives snapping on a coordinate model rather than a box model. This requires a lot of manual calculations in figuring out the correct coordinates from the box model; and also makes sensible scroll-snap settings dependent on the relative sizes of the viewport and the snappable contents, causing problems for users are unexpectedly large and/or small screens (a problem commonly ignored by many authors).
This proposal builds off of roc's model, using an area-snapping model to intelligently handle adaptation to multiple screen sizes. It also adds group alignment as a built-in concept, rather than requiring authors to build one in JavaScript.
Use Cases {#use-cases}
======================
<div class="example">
Use Case 1: Snapping to the start or middle of each box
e.g. address book (start) or photo album (middle)
1. Snapping to 0.25rem above the top of each heading
<pre class="lang-css">
:root { scroll-snap-type: proximity; }
h1, h2, h3, h4, h5, h6 {
scroll-snap-align: start;
scroll-snap-area: 0.25em;
}
</pre>
2. Snapping to the center of each photo
<pre class="lang-css">
:root { scroll-snap-type: mandatory; }
img { scroll-snap-align: center; }
</pre>
</div>
<div class="example">
Use Case 2: Snapping to the start or middle of a group of boxes,
where the number of boxes depends on how many fit in the viewport
e.g. scrolling image galleries
1. Snapping to the top of each "page" of address book entries in a list of entries
<pre class="lang-css">
:root {
scroll-snap-type: proximity;
scroll-group-align: start;
}
article {
scroll-snap-align: group;
}
</pre>
</div>
<div class="example">
Use Case 3: Snapping to boxes (or points) in 2D
e.g. on a map, where you want to snap points of interest to the
center, or a flow-chart diagram, where you want to snap the edges
of each box into the visible area. In both cases, you don't want
objects wholly outside the visible area to influence snapping.
1. Snapping each flow chart entry to within the viewport when it falls near the edge:
<pre class="lang-css">
:root {
scroll-snap-type: proximity;
}
li {
scroll-snap-align: edges;
}
</pre>
2. Snapping each city on a map to the center of the viewport,
but only once it gets near the center in both dimensions:
<pre class="lang-css">
:root {
scroll-snap-type: proximity;
}
.city {
scroll-snap-align: center;
}
</pre>
</div>
<div class="example">
Use Case 4: Slideshow, where successive slides are arranged horizontally,
and sometimes "detail" slides are placed below the "main" slide for that point.
<pre class="lang-html">
<div class="slides">
<div class="slide">...</div>
<div class="slide">...</div>
<div class="slide details">
<div class="slide">...</div>
<div class="slide">...</div>
</div>
<div class="slide">...</div>
</div>
<style>
.slides {
display: flex;
flex-flow: row;
scroll-snap-type: mandatory;
overflow-x: scroll;
width: 100vw;
height: 100vh;
}
.slide {
scroll-snap-align: edges;
width: 100vw;
min-height: 100vh;
}
.slide.details {
display: flex;
flex-flow: column;
scroll-snap-type: mandatory;
overflow-y: scroll;
}
</style>
</pre>
</div>
Overview of Change {#proposal}
==============================
On the scroll container:
<table class=data>
<thead>
<tr>
<th>Spec
<th>Proposal
<th>Priority
<tbody>
<tr>
<td>'scroll-snap-type'
<td>'scroll-snap-type' (no change)
<td>High priority
<tr>
<td>''scroll-snap-destination: <<position>>''
<td>''scroll-snap-padding: [ <<length>> | <<percentage>> ]{1,4}''
<td>
<tr>
<td>'scroll-snap-points-x'
<td>'scroll-snap-points-x'
<td>
<tr>
<td>'scroll-snap-points-y'
<td>'scroll-snap-points-y'
<td>
</table>
On the children:
<table class=data>
<thead>
<tr>
<th>Spec
<th>Proposal
<th>Priority
<tbody>
<tr>
<td>''scroll-snap-coordinate: <<position>>#''
<td>''scroll-snap-align: [ x | y | block | inline | xy ] [ none | start | end | edges | <<percentage>> ]{1,2}''
<td>High priority
<tr>
<td>n/a
<td>''scroll-snap-area: [ border-box | margin-box ] || <<length>>{1,4}''
<td>High priority
<!--
<tr>
<td>n/a
<td>''scroll-snap-scope: infinite | finite''
<td>Only ''finite'' is really necessary to handle all use cases, however UAs might want ''infinite'' as the initial value for performance reasons.
-->
</table>
Scroll Snapping Model {#snap-model}
=====================
This module introduces control
E750
over <dfn lt="scroll snap position" local-lt="snap position">scroll snap positions</dfn>,
which are scroll positions that produce particular alignments
of content within a scrollable viewport.
Using the 'scroll-snap-type' propoperty on the relevant <a>scroll container</a>,
the author can request a particular bias
for the viewport to land on a valid <a>snap position</a>
during scrolling operations.
Valid <a>snap positions</a> can be specified
as a particular alignment ('scroll-snap-align')
of an element's <a>scroll snap area</a> ('scroll-snap-area', defaulting to its margin box)
within the <a>scroll container</a>’s <a>snap viewport</a>
(its viewport, as reduced by 'scroll-snap-padding').
This is conceptually equivalent to specifying the alignment of
an <a>alignment subject</a> within an <a>alignment container</a>.
The scroll position that satisfies the specified alignment
is a valid <a>snap position</a>.
Valid <a>snap positions</a> can also be specified explicitly
as coordinates of the <a>scrollable area</a>
with the 'scroll-snap-points-x' and 'scroll-snap-points-y' properties.
Scroll Snapping Container {#snap-container}
=========================
Scroll Snapping Rules: the 'scroll-snap-type' property {#snap-type}
----------------------
<pre class="propdef">
Name: scroll-snap-type
Value: none | proximity | mandatory
Initial: none
Applies to: <a>scroll containers</a>
Inherited: no
Percentages: n/a
Computed value: as specified
Animatable: no
Media: interactive
</pre>
The 'scroll-snap-type' property is used to define
how strictly <a>snap positions</a> are enforced on the <a>scroll container</a>
(by forcing an adjustment to the scroll offset).
It intentionally does not specify nor mandate any precise animations or physics used to enforce those <a>snap positions</a>;
this is left up to the user agent.
Values are defined as follows:
<dl dfn-type=value dfn-for=scroll-snap-type>
<dt><dfn>none</dfn>
<dd>
The visual viewport of this <a>scroll container</a>
must ignore <a>snap positions</a>, if any, when scrolled:
all scroll positions are equally valid.
<dt><dfn>proximity</dfn>
<dd>
The visual viewport of this <a>scroll container</a>
may come to rest at a <a>snap position</a> at the termination of a scroll
at the discretion of the UA given the parameters of the scroll.
If the content changes such that the visual viewport
would no longer rest at a <a>snap position</a>
(e.g. content is added, moved, deleted, resized),
the scroll offset may be modified to maintain this guarantee.
<dt><dfn>mandatory</dfn>
<dd>
The visual viewport of this <a>scroll container</a>
is guaranteed to rest at a <a>snap position</a>
when there are no active scrolling operations.
That is, it must come to rest at a <a>snap position</a>
at the termination of a scroll, if any exist.
(If none exist, then no snapping occurs.)
If the content changes such that the visual viewport
would no longer rest at a <a>snap position</a>
(e.g. content is added, moved, deleted, resized),
the scroll offset must be modified to maintain this guarantee.
Issue: The underlying MS model has a notion of "single mandatory",
where the very next snap point automatically absorbs all the inertia,
even if a fling would normally take you past two or more snap points.
According to Matt, this is actually what MS implemented for ''mandatory''
(need to run tests),
but it's definitely <em>not</em> what Safari implemented.
Do we need a third value to capture this semantic?
Useful, for example, to let someone fling through a post they dont' care about
and automatically catch the next one
in an RSS reader or similar.
</dl>
Issue: See <a href="https://lists.w3.org/Archives/Public/www-style/2015Jul/0452.html">discussion on snapping in response to layout changes</a>.
Scroll Snapping Window: the 'scroll-snap-padding' property {#snap-padding}
-----------------------
<pre class="propdef">
Name: scroll-snap-padding
Value: [ <<length>> | <<percentage>> ]{1,4}
Initial: 0
Applies to: <a>scroll containers</a>
Inherited: no
Percentages: n/a
Computed value: as specified
Animatable: no
Media: interactive
</pre>
The 'scroll-snap-padding' property defines the <dfn local-lt="snap viewport">scroll snap viewport</dfn>--
the area of the viewport that is used as the <a>alignment container</a>
when aligning a <a>scroll snap area</a> to a <a>snap position</a>.
Values are interpreted as for 'padding',
and specify inward offsets from each side of the viewport.
<div class="example">
In this example, points of interest in a map are centered
within the portion of the viewport that does not include the toolbar overlay.
<pre>
map {
overflow: scroll;
scroll-snap-type: proximity;
scroll-snap-padding: 3em 0 0 0;
}
toolbar {
position: absolute;
margin: 0.5em;
top: 0; left: 0; right: 0;
height: 2em;
}
city {
scroll-snap-align: center;
}
</pre>
</div>
This property is a <a>shorthand property</a> that sets
all of the <a href="#longhands"><css>scroll-snap-padding-*</css> longhands</a>
in one declaration.
Coordinate-based Snapping {#snap-points}
=========================
Scroll Snapping Coordinates: the 'scroll-snap-points-x' and 'scroll-snap-points-y' properties {#coordinates}
----------------------------
<pre class="propdef">
Name: scroll-snap-points-x, scroll-snap-points-y
Value: none | repeat( [ <<length>> | <<percentage>> ])
Initial: none
Applies to: <a>scroll containers</a>
Inherited: no
Percentages: relative to the size of the <a>snap viewport</a> in the appropriate axis
Computed value: as specified, with lengths made absolute and clamped (see below)
Animatable: no
Media: interactive
</pre>
The 'scroll-snap-points-x' and 'scroll-snap-points-y' properties
are used to define <a>snap positions</a>
by specifying coordinates against the <a>scrollable area</a> of the <a>scroll container</a>.
<dl dfn-type="value" dfn-for="snap-points-x, snap-points-y">
<dt><dfn>none</dfn>
<dd>
No <a>snap areas</a> are defined by this <a>scroll container</a>.
Contained elements may still define <a>snap areas</a> on this <a>scroll container's</a> behalf.
<dt><dfn>repeat([ <<length>> | <<percentage>> ])</dfn>
<dd>
Defines start-<a href="#scroll-snap-alignment">aligned</a> <a>snap areas</a>
that span the <a>scrollable area</a> in the appropriate axis,
starting from the <a>start</a> edge of the <a>scrollable area</a>
and spanning every <<length>> across the entire <a>scrollable area</a>,
with the end edge of the last <a>snap area</a> occuring at or past the end edge of the <a>scrollable area</a>.
<span class="note">Note that the last <a>snap position</a>
effectively gets pulled into the scrollable area as necessary
to prevent overscrolling, see [[#choosing]].</span>
Negative values are invalid.
User agents must define a UA-defined minimum <<length>> greater than 0
(recommended ''1px''),
and clamp the used value to that minimum.
</dl>
Coordinates specified by 'scroll-snap-points-x' and 'scroll-snap-points-y'
are not affected by 'scroll-snap-padding'/'scroll-snap-destination'.
Issue: Or should they also be affected by 'scroll-snap-padding'?
Also we're effectively assuming start-alignment here, is that what we want?
Or do we want to allow other alignments?
Issue: Should we add <css>start-edge</css> and <css>end-edge</css> keywords here, so that the start and end of the scrollable area can be defined as reachable?
This would be good for e.g. maps.
(See <a href="https://lists.w3.org/Archives/Public/www-style/2015Jul/0453.html">Matt Rakow's take</a> on not having <css>start</css> or <css>end</css> here.)
Note, tho, that Safari adds start/end automatically
(<a href="https://www.webkit.org/blog/4017/scroll-snapping-with-css-snap-points/">document at end of their announcement post</a>).
Issue: It was <a href="https://lists.w3.org/Archives/Public/www-style/2015Jul/0453.html">suggested</a> that repeat() be mutually exclusive with element-based snap positions. Is there a better way to integrate this than having the initial value here be "elements"?
Issue: This needs logical equivalents (-block/-inline instead of -x/-y).
Element-based Snapping {#element}
======================
Scroll Snapping Area: the 'scroll-snap-area' property {#scroll-snap-areas}
---------------------
<pre class="propdef">
Name: scroll-snap-area
Value: [ border-box | margin-box ] || <<length>>{1,4}
Initial: border-box
Applies to: all elements
Inherited: no
Computed value: as specified, with lengths made absolute
Animatable: yes, if ''border-box''/''margin-box'' are constant
Media: interactive
</pre>
Specifies the <dfn lt="scroll snap area" local-lt="snap area">scroll snap area</dfn>
that is used for snapping this box to the viewport.
<<length>> values give outsets (similar to 'margin' or 'border-image-outset').
This property is a <a>shorthand property</a> that sets
all of the <a href="#longhands"><css>scroll-snap-area-*</css> longhands</a>
in one declaration.
Scroll Snapping Alignment: the 'scroll-snap-align' property {#scroll-snap-alignment}
--------------------------
<pre class="propdef">
Name: scroll-snap-align
Value: none | [ block | inline ]? [ edges | <<snap-alignment>> ] |
[ none | edges | <<snap-alignment>> ]{2} |
point <<snap-alignment>>{1,2}
Initial: none
Applies to: all elements
Inherited: no
Percentages: refer to size of scroll container's <a>snap viewport</a> <em>minus</em> size of box's <a>snap area</a>
Computed value: an optional ''point'' keyword, plus one or a pair of alignment values
each consisting of either a ''none'' or ''edges'' keyword or a percentage
Animatable: as percentage, if only the percentage differs
Media: interactive
</pre>
Specifies the element's <a>snap position</a> as an alignment of
its <a>snap area</a> (as the <a>alignment subject</a>)
within the viewport's <a>snap viewport</a> (as the <a>alignment container</a>).
The <a>scroll alignment values</a> can be specified per-axis,
or as a simultaneous 2D alignment position.
<pre class="prod">
<dfn for=scroll-snap-align><<snap-alignment>></dfn> = center | [ start | end ] <<percentage>>?
</pre>
Issue: This is a subset of the L4 <<position>> syntax
that works within the constraint of an axis.
It also aligns with the <<self-position>> syntax from [[CSS-ALIGN-3]] (see e.g. 'align-self').
We could simplify to ''center | start | end'' by dropping <<percentage>>
(which would be a true subset of <<self-position>>),
or expand to a full logical/physical combination syntax
(as a fuller, and therefore more complicated, subset of <<position>>).
<div class="example">
The following example aligns the start edge of the box's <a>snap area</a>
to the start edge of the scroll container's <a>snap viewport</a>:
<pre>section { scroll-snap-align: start; }</pre>
The following example aligns the center of each city
to the center of the scroll container's <a>snap viewport</a>,
snapping only when the city is centered in both axes:
<pre>city { scroll-snap-align: point center; }</pre>
The following example aligns the center of each photo
to the center of the scroll container's <a>snap viewport</a>,
snapping independently in each axis:
<pre>img { scroll-snap-align: center; }</pre>
</div>
'scroll-snap-align' has four distinct syntaxes,
depending on what <a>snap positions</a> you wish the element to specify:
<dl>
<dt id=scroll-snap-align-none>none
<dd>
Specifies that the box contributes no <a>snap positions</a> at all,
i.e. both axes compute to ''scroll-snap-align/none''.
<dt id=scroll-snap-align-single>[ block | inline ]? [ edges | <<snap-alignment>> ]
<dd>
Specifies a <a>1D snap position</a>
in either the <a>block</a> or <a>inline</a> axis.
If a <dfn for=scroll-snap-align type=value>block</dfn> or <dfn for=scroll-snap-align type=value>inline</dfn> keyword is specified,
the specified alignment is for that axis,
and the other axis computes to ''scroll-snap-align/none''.
Otherwise,
the used axis is automatically chosen:
* If the box’s nearest <a>scroll container</a> is only scrollable in one axis
(only one axis has its 'overflow' set to ''overflow/auto'' or ''overflow/scroll'')
the scrollable axis is chosen.
* Otherwise, the nearest <a>scroll container</a>’s <a>block axis</a> is chosen.
<dt id=scroll-snap-align-double>[ none | edges | <<snap-alignment>> ]{2}
<dd>
Specifies two <a>1D snap positions</a>,
one in each axis.
The first value is in the <a>inline</a> axis,
and the second is in the <a>block</a> axis.
<dt id=scroll-snap-align-2d>point <<snap-alignment>>{1,2}
<dd>
The element declares a <a>2D snap position</a>.
If both alignments are given,
the first applies to the <a>inline</a> axis
and the second applies to the <a>block</a> axis.
If only one is given,
the position applies to both axises.
</dl>
Since the purpose of scroll snapping is to align content within the viewport
for optimal viewing:
in all cases, the specified alignment creates a valid <a>snap position</a>
only if at least part of the <a>snap area</a> is within the <a>snap viewport</a>.
For example, a <a>snap area</a> is top-aligned to the <a>snap viewport</a>
if its top edge is coincident with the <a>snap viewport</a>’s top edge;
however, this alignment is nonetheless not a valid <a>snap position</a>
if the entire <a>snap area</a> is outside the <a>snap viewport</a>.
<details class="why">
<summary>Why</summary>
As the <a href="https://www.webkit.org/blog/4017/scroll-snapping-with-css-snap-points/">WebKit implementers point out</a>,
extending a snap edge infinitely across the canvas
only allows for snapping gridded layouts,
and produces odd behavior for the user
when off-screen elements do not align
with on-screen elements.
(If this requirement is onerous for implementers however,
we can default to a gridded behavior
and introduce a switch to get smarter behavior.)
</details>
For all of these values,
the <a>block</a> or <a>inline</a> axis
is relative to the element's parent's <a>writing mode</a>.
<span class="issue">Is this the correct writing mode to compute against?
Or should it be the scroll container's writing mode?</span>
The <dfn export>scroll alignment values</dfn> are defined as follows:
<dl dfn-for=scroll-snap-align dfn-type=value>
<dt><dfn>none</dfn>
<dd>
This box does not define a <a>snap position</a> in the specified axis.
<dt><dfn>start</dfn>
<dd>
Start alignment of this box's <a>scroll snap area</a>
within the <a>scroll container</a>'s <a>snap viewport</a>
is a valid <a>snap position</a>.
<dt><dfn>end</dfn>
<dd>
End alignment of this box's <a>scroll snap area</a>
within the <a>scroll container</a>'s <a>snap viewport</a>
is a valid <a>snap position</a>.
<dt><dfn>center</dfn>
<dd>
Center alignment of this box's <a>scroll snap area</a>
within the <a>scroll container</a>'s <a>snap viewport</a>
is a valid <a>snap position</a>.
<dt><dfn><<percentage>></dfn>
<dd>
Percentage alignment of this box's <a>scroll snap area</a>
within the <a>scroll container</a>'s <a>snap viewport</a>
is a valid <a>snap position</a>,
where the percentage represents a position between
''scroll-snap-align/start'' alignment and ''scroll-snap-align/end'' alignment.
''0%'' matches the given alignment keyword (''scroll-snap-align/start'' or ''scroll-snap-align/end'').
Percentages from the ''end'' compute to start-based percentages (as 100% − <<percentage>>).
<dt><dfn>edges</dfn>
<dd>
Both start alignment and end alignment of this box's <a>scroll snap area</a>
within the <a>scroll container</a>'s <a>snap viewport</a>
are valid <a>snap positions</a>.
</dl>
Note: Remember that in <a>vertical writing modes</a> the block and inline axes
correspond to the x and y axes, and not the y and x axes, respectively.
If the <a>snap area</a> is larger than the <a>snap viewport</a> in a particular axis,
then any scroll position in which the <a>snap area</a> covers the <a>snap viewport</a>
is a valid <a>snap position</a> in that axis.
The UA may use the specified alignment as a more precise target
for certain scroll operations (e.g. inertial scrolling or explicit paging).
<div class="example">
For example, imagine a photo as the area, or a slide in a slideshow.
The author wants mandatory snapping from item to item,
but if the item happens to be larger than your viewport,
you want to be able to scroll around the whole thing once you're over it.
Since the <a>snap area</a> is larger than the <a>snap viewport</a>,
while the area fully fills the viewport,
the container can be scrolled arbitrarily and will not try to snap back to its aligned position.
However, if the container is scrolled such that the area
no longer fully fills the viewport in an axis,
the area resisting outward scrolling
until you fling out or pull it sufficiently to trigger snapping to a different <a>snap position</a>.
</div>
<details class="why">
<summary>Why no <<length>> or <<position>> values?</summary>
The values here represent alignments
(in the sense of 'align-self' and 'justify-self'),
so are consistent with that syntax.
We chose to use this simpler syntax without lengths
because the 'scroll-snap-area' concept already provides length offsets--
but does so in a smarter way, that degrades better on small screens
(see above) because it provides more information (a box, rather than a point) to the UA.
We could have also added lengths here,
but it would provide multiple ways to do the same thing,
which is additional overhead for implementation, testing, and (most importantly) author learning.
It also introduces more room for cascading errors,
and guides authors in the wrong direction--
away from 'scroll-snap-area'.
</details>
<!--
### Combining 1D and 2D Snap Alignments ### {#combo-snapping}
The following algorithm defines
how to combine 1D (''edges'', ''start'', or ''end'')
and 2D (''center'' or <<position>>)
snap alignments
in the same scroller:
1. Find the closest block-axis snapping edge in the scroll direction.
2. Find the closest inline-axis snapping edge in the scroll direction.
3. Compute the "edge displacement" as the euclidean distance between the current scroll position
and what the scroll position would be if the scroll container were snapped to the aforementioned two lines.
4. Find the closest snap *point* in the scroll direction,
measured by euclidean distance from the current scroll position.
The difference is the "point displacement".
5. If the edge displacement is smaller than the point displacement, snap to those edges.
Otherwise, snap to the point.
Issue: Think about how mandatory/finite would work when there's nothing within range to snap to.
-->
Snapping Mechanics {#snap}
==========================
The precise model algorithm to select a <a>snap position</a> to snap to
is intentionally left mostly undefined,
so that user agents can take into account sophisticated models of user intention and interaction
and adjust how they respond over time,
to best serve the user.
This section defines some useful concepts to aid in discussing scroll-snapping mechanics,
and provides some guidelines for what an effective scroll-snapping strategy might look like.
User agents are encouraged to adapt this guidance
and apply their own best judgement
when defining their own snapping behavior.
It also provides a small number of behavior requirements,
to ensure a minimum reasonable behavior that authors can depend on
when designing their interfaces with scroll-snapping in mind.
Types of Scrolling Gestures {#scroll-types}
-------------------------------------------
There are at least three distinct form of scroll gestures that a user might perform on a page,
which can reasonably trigger different snapping behaviors:
: <dfn export local-lt="explicit" lt="explicit scroll">explicit scrolling</dfn>
:: A scroll is <a>explicit</a> if the user is explicitly scrolling to a well-defined and obvious end-point.
This includes gestures such as:
* a panning gesture,
released without momentum
* manipulating the scrollbar "thumb" explicitly
* programmatically scrolling via APIs such as {{Window/scrollTo()}}.
: <dfn export local-lt="inertial" lt="inertial scroll">inertial scrolling</dfn>
:: A scroll is <a>inertial</a> if it is a gesture where the user "flings" the scroll position,
indicating a direction and a momentum for the scroll,
but no well-defined and intentional end-point.
User agents tend to implement <a>inertial</a> scrolls
by simulating a "friction" force that gradually reduces the scroll's momentum,
or by otherwise gradually reducing the speed in a way feels "natural"
and respects the user's intention.
The scroll position that an <a>inertial</a> scroll would naturally land on
without further intervention is the <dfn noexport>natural end-point</dfn>.
: <dfn export local-lt="semantic" lt="semantic scroll">semantic scrolling</dfn>
:: A scroll is <a>semantic</a> if it expresses a preferred direction to scroll in,
but not a geometric amount of scrolling,
or a specific "momentum" to a fling.
This is most commonly from pressing an arrow key;
for example, pressing the Down key indicates that you want to scroll down some amount.
Additionally, because page layouts usually align things vertically and/or horizontally,
UAs sometimes <dfn export>axis-lock</dfn> a scroll when the gesture triggering it
is sufficiently vertical or horizontal.
An <a>axis-locked</a> scroll is bound to only scroll along that axis.
This prevents,
for example,
a <em>nearly</em> horizontal fling gesture from gradually drifting up or down as well,
because it is very difficult to fling in a precisely horizontal line.
1D vs 2D Snap Position {#snap-dimensions}
-----------------------------------------
There are two distinct forms of <a>snap positions</a> that a <a>scroll container</a> might contain:
: <dfn export local-lt="1D" lt="1D snap position">1D snap position</dfn>
:: A <a>1D snap position</a> indicates a desired scroll position
in one axis of the <a>scroll container</a> only,
with no preference for what the other axis's scroll position should be.
Note:
This is the “default” type of <a>snap position</a>
that most elements will want to use,
and so the ''scroll-snap-align'' property intentionally makes it the simplest to specify.
Note: An element can declare two <a>1D snap positions</a>,
one in each axis.
These represent two independent <a>snap position</a> preferences,
not a single <a>2D snap position</a>:
if one of the element's snap positions is chosen in one axis,
this has no bearing on the other dimension's <a>snap position</a>--
it might be chosen,
or another element's <a>snap position</a> might be chosen for that axis,
or that axis might not snap at all.
: <dfn export local-lt="2D" lt="2D snap position">2D snap position</dfn>
:: A <a>2d snap position</a> indicates a desired <a>snap position</a>
in both axises at once,
aligning the <a>snap area</a> of an element
to the specified 2D position in the <a>scroll container</a>’s <a>snap viewport</a>.
This type of <a>snap position</a> is intended for "two-dimensional" panning-type layouts,
such as cities on a map
(using ''proximity'' 2D snap positions to snap a city to the center of the display when it gets close),
or a tiled image gallery
(using ''mandatory'' 2D snap positions to force each image to be centered on the screen).
Mixing <a>1D</a> and <a>2D</a> snap positions within a single <a>scroll container</a> is discouraged,
as the behavior can be hard to predict.
Nevertheless, this specification provides guidance on how to deal with mixed <a>snap positions</a>,
as the design of the properties does not prevent such a mixture.
Choosing Snap Positions {#choosing}
-----------------------------------
A <a>scroll container</a> can have many <a>snap areas</a>
scattered throughout its <a>scrollable area</a>.
A naive algorithm for selecting a <a>snap position</a>
can produce behavior that is unintuitive for users,
so care is required when designing a selection algorithm.
Here are a few pointers that can aid in the selection process:
* <a>Snap positions</a> should be chosen to minimize the distance between the end-point
(or the <a>natural end-point</a>)
and the final snapped scroll position,
subject to the additional constraints listed in this section.
* <a>2D snap positions</a> are all-or-nothing;
if a <a>2D snap position</a> is chosen to align to,
the <a>scroll container</a> must set its scroll position
according to the snap positions's preferred scroll position in <em>both</em> axises;
the <a>scroll container</a> <em>must not</em> “partially align” to a <a>2D snap position</a>
by taking its <a>snap position</a> in one axis
and aligning the other axis according to something else.
* If a scroll is <a>axis-locked</a>,
any <a>1D</a> snap positions in the other axis should be ignored.
<a>2D</a> snap positions should be penalized in the selection process
according to the amount of other-axis scrolling they would cause.
* <a>Snap positions</a> should be ignored if their elements are far outside of the "corridor"
that the <a>snap viewport</a> defines as it moves through the <a>scrollable area</a>
during an <a>inertial scroll</a>,
or a hypothetical "corridor" in the direction of a <a>semantic scroll</a>,
or the <a>snap viewport</a> after an <a>explicit scroll</a>.
(This is to prevent a far-offscreen element
from having difficult-to-understand effects
on the scroll position.)
* User agents <em>must</em> ensure that a user can "escape" a <a>snap position</a>,
regardless of the scroll method.
For example, if the snap type is ''mandatory''
and the next <a>snap position</a> is more than two screen-widths away,
a naïve "always snap to nearest" selection algorithm would “trap” the user
if they were panning with a touch gesture;
a sufficiently large distance would even trap fling scrolling!
Instead, a smarter algorithm that only returned to the starting <a>snap position</a>
if the end-point was a fairly small distance from it,
and otherwise ignored the starting snap position,
would give better behavior.
(This implies that a <a>semantic scroll</a> must always ignore the starting <a>snap positions</a>.)
* If the most appropriate <a>snap position</a> is unreachable,
such that aligning to it would require scrolling the <a>scroll container</a>’s viewport
8096
past the edge of its <a>scrollable area</a>,
the <a>scroll container</a> must be scrolled <em>as much as possible</em> in each relevant axis
toward the desired <a>snap position</a>.
This is the <em>used</em> <a>snap position</a> corresponding to that <a>snap position</a>;
that is, the UA must “snap” to this position just as it would have if it were the actual specified alignment.
* A user agent <em>may</em> want to ignore ''mandatory'' <a>snap positions</a>
that are sufficiently far away from the scroll's end point,
to ensure that users are able to see everything on the page
even if the page author did not use snap position well,
even if this means that a <a>scroll container</a> is not aligned to a snap position sometimes.
(This is already taken care of for overly-large elements,
which automatically expand the valid snap position
so a user can pan to see the entire element.)
Issue: This would prevent space-travel effects. I think we should remove this.
<!--
Group-based Snapping {#group}
========================
Issue: This section will likely be dropped.
Collects the <a>scroll snap areas</a> of all group-snapped boxes,
segments them into groups that will fit within the viewport,
then creates synthesized <a>scroll snap areas</a> to represent each group.
The <a>snap positions</a> introduced by these boxes
is then the 'scroll-group-align' alignment of each such group
within the viewport.
(Note that such areas may overlap,
if group-snapped boxes are arranged in an overlapping pattern.)
This is a simple form of "scrolling by pages".
<div class="example">
Use Case 1: Snapping to the top of each "page" of address book entries in a list of entries.
<pre class="lang-css">
:root {
scroll-snap-type: proximity;
scroll-group-align: start;
}
article {
scroll-snap-align: group;
}
</pre>
</div>
<div class="example">
Use Case 2: Scrolling an article to the first paragraph that hasn't been completely read.
<pre class="lang-css">
article {
scroll-snap-type: proximity;
scroll-group-align: start;
}
article > * {
scroll-snap-align: group;
}
</pre>
</div>
<div class="example">
Use Case 3: Scrolling image gallery, a la Pinterest, where images are packed tightly on the page.
<pre class="lang-css">
.gallery {
scroll-snap-type: proximity;
scroll-group-align: center;
}
.gallery > img {
scroll-snap-align: group;
}
</pre>
</div>
Turning On Group Snapping: the ''group'' value of 'scroll-snap-align' {#scroll-snap-align-group}
-------------------------
<pre class="propdef partial">
Name: scroll-snap-align
New values: group
</pre>
The <dfn value for=scroll-snap-align>group</dfn> value
specifies that this element's scroll snap area should be group-aligned to the viewport.
Aligning the Group: the 'scroll-snap-group' property {#scroll-snap-group}
-----------------
<pre class="propdef">
Name: scroll-snap-group-align
Value: <'scroll-snap-align'>
Initial: start
Applies to: all elements
Inherited: no
Computed value: as specified
Animatable: no
Media: interactive
</pre>
Specifies the alignment of a group-snapped group's area within the viewport.
-->
Appendix A: Longhands {#longhands}
=====================
Physical Longhands for 'scroll-snap-padding' {#padding-longhands-physical}
--------------------------------------------
<pre class="propdef">
Name: scroll-snap-padding-top, scroll-snap-padding-right, scroll-snap-padding-bottom, scroll-snap-padding-left
Value: <<length>>
Initial: border-box
Applies to: all elements
Inherited: no
Computed value: as specified, with lengths made absolute
Animatable: as length, if ''border-box''/''margin-box'' are constant
Media: interactive
</pre>
These <a>longhands</a> of 'scroll-snap-padding' specify
the top, right, bottom, and left
edges of the <a>snap viewport</a>,
respectively.
Flow-relative Longhands for 'scroll-snap-padding' {#padding-longhands-logical}
-------------------------------------------------
<pre class="propdef">
Name: scroll-snap-padding-inline-start, scroll-snap-padding-block-start, scroll-snap-padding-inline-end, scroll-padding-block-end
Value: <<length>>
Initial: border-box
Applies to: all elements
Inherited: no
Computed value: as specified, with lengths made absolute
Animatable: as length, if ''border-box''/''margin-box'' are constant
Media: interactive
</pre>
These <a>longhands</a> of 'scroll-snap-padding' specify
the block-start, inline-start, block-end, and inline-end
edges of the <a>snap viewport</a>,
respectively.
<pre class="propdef">
Name: scroll-snap-padding-block, scroll-snap-padding-inline
Value: <<length>>{1,2}
Initial: border-box
Applies to: all elements
Inherited: no
Computed value: as specified, with lengths made absolute
Animatable: as length, if ''border-box''/''margin-box'' are constant
Media: interactive
</pre>
These <a>shorthands</a> of 'scroll-snap-area-block-start' + 'scroll-snap-area-block-end'
and 'scroll-snap-area-inline-start' + 'scroll-snap-area-inline-end'
are <a>longhands</a> of 'scroll-snap-padding', and
specify the block-axis and inline-axis
edges of the <a>snap viewport</a>,
respectively.
If two values are specified, the first gives the start value
and the second gives the end value.
Physical Longhands for 'scroll-snap-area' {#area-longhands-physical}
-----------------------------------------
<pre class="propdef">
Name: scroll-snap-area-top, scroll-snap-area-right, scroll-snap-area-bottom, scroll-snap-area-left
Value: [ border-box | margin-box ] || <<length>>
Initial: border-box
Applies to: all elements
Inherited: no
Computed value: as specified, with lengths made absolute
Animatable: as length, if ''border-box''/''margin-box'' are constant
Media: interactive
</pre>
These <a>longhands</a> of 'scroll-snap-area' specify
the top, right, bottom, and left
edges of the <a>scroll snap area</a>,