The CSS snapport is the alignment-container region used when CSS scroll snapping aligns a target's CSS scroll snap area. It is derived from the CSS scrollport by the inward offsets specified through CSS scroll padding. This lets snapping use a preferred viewing region rather than always aligning to the scrollport's outer edges.[ref]
CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §3, snap model; §4.2, Scroll Snapport: scroll-padding
For an own two-dimensional example, take a -by- CSS pixel scrollport, with physical coordinates increasing rightward and downward. Declare
scroll-padding: 10px 20px 30px 40px;, in top/right/bottom/left order. The snapport iswith width and height . The scrollport itself remains by .Suppose a target's snap area begins at content coordinate and is pixels wide, with no scroll margin. Assume horizontal left-to-right layout, no transforms and an adequate reachable scrolling range. For start alignment, its displayed left edge must equal the snapport's left edge:With zero left scroll padding, the same candidate would instead have . The inset changes the alignment target without changing the element's position in its content layout.
An inset can accommodate a toolbar obscuring part of the viewing region, or provide space around a focused target. It does not itself clip the excluded region, change the CSS scroll origin or resize the content. Ordinary box padding and CSS scroll padding consequently have different effects.[ref]
CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §4.2, optimal viewing region and no effect on layout, origin or actual visibility
The alignment must also be interpreted with the appropriate CSS writing mode and reachable offsets. Start, end and center are alignments between the CSS scroll snap area and the CSS snapport, while selection among candidates belongs to the snapping rules. The numerical example solves one candidate; it does not predict which gesture will select it or prescribe an animation.[ref]
CSS scroll padding defines inward offsets from a CSS scrollport to establish an optimal viewing region. In a snap container that region is the CSS snapport, used to align CSS scroll snap areas. The
scroll-padding shorthand sets its sides, while individual longhands can control one side.[ref]CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §4.2, scroll-padding and optimal viewing region
For an own example, take a -by- CSS pixel scrollport and set
scroll-padding: 10%;. Percentages resolve against the corresponding scrollport dimension: left and right are pixels each, top and bottom each. In physical coordinates the optimal region iswith dimensions by . The declaration gives the same percentage on each side, not the same absolute number of pixels.[ref]An explicit
scroll-padding-top: 50px can reserve room in the preferred viewing region when an overlay obscures the top of a scrolling panel. This does not itself create the overlay or change the content's normal layout. It tells scrolling operations where a useful visible alignment should lie.The initial value
auto leaves the offset to the user agent. The pinned specification says it should generally resolve to zero, while allowing heuristics that choose a nonzero value in appropriate cases. Code that needs the example's explicit geometry should therefore state its offsets instead of silently treating every automatic value as zero.[ref]CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §4.2, auto and heuristic example
These offsets do not clip the excluded strip, resize the scrollport, change the CSS scroll origin or redefine the CSS initial scroll position. They affect the optimal region for operations such as targeting, focusing and paging; the property applies to scroll containers even when they are not snap containers.[ref]
CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §4.2, applicability and effects on scrolling versus layout/visibility
CSS scroll margin describes outsets on the target side, whereas CSS scroll padding describes insets on the container side. Using both requires aligning the resulting two regions rather than adding ordinary box-model padding to the element and assuming it has the same effect.
Articles by others on the same topic
There are currently no matching articles.