CSS scroll margin 2026-11-05
CSS scroll margin supplies outsets around an element's transformed border bounds to define its CSS scroll snap area. The
scroll-margin shorthand assigns top, right, bottom and left values using the usual one-to-four-value ordering. In the pinned specification these values are lengths, rather than percentages.[ref]CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §5.1, scroll-margin syntax, ordering and area construction
For an own example, let an untransformed CSS border box occupy in content coordinates measured in CSS pixels. Set
scroll-margin: 20px 10px;. The first value applies at top and bottom, and the second at left and right, giving the snap areaThe box itself is still by pixels; the alignment region is by .Suppose a reachable horizontal start alignment should place this area's left edge at coordinate within the CSS snapport. With a left-to-right horizontal convention, the candidate offset satisfies , giving . Without the left outset, it would instead be . The extra target-side room changes the alignment computation without changing where the border is laid out in the content.
The construction uses the axis-aligned bounding box of the transformed border box before adding the outsets. A rotated CSS transform can therefore affect the base rectangle, even though the resulting snap area remains rectangular in the scroll container's coordinates.[ref]
CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §5.1, transformed bounds and axis alignment
CSS scroll margin and ordinary layout margins serve different purposes. The former does not assign this extra space between neighboring elements in normal layout. It is also distinct from CSS scroll padding, which adjusts the viewing/alignment region on the container side.
CSS scroll padding 2026-11-05
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.
CSS scroll snap area 2026-11-05
A CSS scroll snap area is the target region aligned within a CSS snapport during CSS scroll snapping. The specification constructs it from the target's transformed CSS border box: find its rectangular bounding box, aligned to the scroll container's coordinate axes, then apply the outsets supplied by CSS scroll margin.[ref]
CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §5.1, scroll-margin and snap-area construction
Consider an untransformed element whose border box occupiesin content coordinates measured in CSS pixels. Set
scroll-margin: 10px 20px 30px 40px;, in top/right/bottom/left order. The snap area becomesIt is pixels wide and high, even though the original border box remains by .For a candidate start alignment, suppose the CSS snapport begins at viewport coordinates and is large enough to contain this area. Use a horizontal left-to-right writing mode and assume adequate reachable scroll ranges. The required offsets satisfygiving . At that position, the element's actual border box appears at ; the extra room comes from aligning the larger snap area, not moving its borders relative to its content.[ref]
CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §5.2, start alignment of snap area within snapport
A CSS transform can change the initial bounding rectangle. The snap area is nevertheless axis-aligned in the scroll container's coordinate space, even if the transformed border is rotated. Its rectangular shape is therefore an alignment construction, not necessarily the painted outline of the element.
CSS scroll margin also differs from an ordinary layout margin: the example's outsets enlarge the snapping region without assigning extra space between neighboring boxes in normal layout. Reachability and visibility still constrain valid snap positions. If an exact alignment would require scrolling beyond the available area, the specification uses the reachable position as far toward that alignment as possible.[ref]
CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §5.1, outsets; §§5.2.1 and 5.2.3, valid visibility and unreachable positions
CSS scroll snapping 2026-11-05
CSS scroll snapping adjusts a CSS scroll container's CSS scroll position to an eligible alignment of content. A target supplies a CSS scroll snap area; the container supplies a CSS snapport, derived from its CSS scrollport and adjusted by
scroll-padding. Aligning these regions defines candidate snap positions.[ref]For an own geometrical example, arrange three consecutive panels, each CSS pixels wide, in a horizontal strip. Give the container a -pixel scrollport, left-to-right coordinates, no gaps, no scroll padding or scroll margins, and no transforms. Aligning each panel's left edge with the viewing region's left edge gives candidate horizontal offsetsAt offset , the second panel occupies the view. At offset , its left edge is still pixels inside the view.
The container can request
overflow-x: auto; scroll-snap-type: x mandatory;, while each panel requests scroll-snap-align: start;. The declarations specify the snapping axis, strictness and target alignment; the example separately stipulates the panel layout. These declarations alone do not arrange three arbitrary elements into a strip.[ref]CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §4.1, scroll-snap-type; §5.2, scroll-snap-align
With
mandatory, a container with a valid snap position must be snapped when scrolling has settled. With proximity, whether it snaps at the end of an operation is left to the user agent under the specified rules. Neither keyword prescribes a universal numerical distance threshold or a particular animation.[ref]CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §4.1.2, strictness; §§3 and 6, snapping mechanics
The candidate geometry also does not uniquely determine which target an input gesture selects. Direction, intended endpoint and the user agent's selection behavior matter. Targets larger than the scrollport have special rules permitting access within the oversized region, so mandatory snapping is not a requirement to hide the middle of every large item.[ref]
CSS Scroll Snap Module Level 1 by World Wide Web Consortium. §5.2.2, oversized snapping boxes; §6.2, choosing snap positions
Useful snapping combines predictable content alignment with access to the content between those alignments. CSS snapport 2026-11-05
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 transform 2026-11-05
A CSS transform changes the coordinate mapping used to render a transformable element. Translation, scaling and rotation are examples of CSS transform functions. Their composition maps local points into the parent coordinate system; the CSS transform origin specifies the point around which the transformation is constructed.[ref]
CSS Transforms Module Level 1 by World Wide Web Consortium. §3, Transform Rendering Model; §§4–5, transform and transform-origin
For an own two-dimensional example, use an ordinary CSS box with
transform-box: border-box; transform-origin: 0 0;, no ancestor transforms, and local coordinates relative to that top-left origin. This fixes the CSS transform reference box and origin explicitly. Ignore the box's placement offset to isolate the transform itself.Using homogeneous column vectors, letThe list
transform: translate(10px, 0) scale(2); gives the product . Applied to point , the scale acts first:Reversing the list to scale(2) translate(10px, 0) gives and the result . The translation is scaled in the reversed composition. Matrix multiplication explains the order dependence.[ref]CSS Transforms Module Level 1 by World Wide Web Consortium. §3, matrix construction and local-to-parent mapping; §9.1, 2D functions
The zero origin is part of the example, not an irrelevant decoration. A different origin adds translations around the listed operations and can change the mapped point. The simple matrix computation also fixes its column-vector convention instead of relying on an ambiguous phrase such as applying functions in order.
For boxes governed by the CSS box model, a transform changes rendering without rearranging the surrounding normal-flow content. It can nevertheless extend CSS overflow, and transformed geometry affects client rectangles. The absence of normal-flow re-layout is therefore not a claim that every geometrical or scrolling quantity stays fixed.[ref]
CSS Transforms Module Level 1 by World Wide Web Consortium. §3, surrounding flow, overflow and client-rectangle effects
The same transformed bounds matter when constructing a CSS scroll snap area. A rendered border can be rotated while its axis-aligned bounding box is used for alignment geometry. Separating layout boxes, coordinate mappings and derived bounds makes these effects easier to calculate.