{"id":282511,"date":"2019-02-12T15:49:09","date_gmt":"2019-02-12T22:49:09","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=282511"},"modified":"2019-05-29T07:29:01","modified_gmt":"2019-05-29T14:29:01","slug":"scroll-padding","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/properties\/s\/scroll-padding\/","title":{"rendered":"scroll-padding"},"content":{"rendered":"

scroll-padding<\/code> is part of the CSS Scroll Snap Module<\/a>. Scroll snapping refers to “locking” the position of the viewport to specific elements on the page as the window (or a scrollable container) is scrolled. Think of a scroll-snapping container like putting a magnet on top of an element that sticks to the top of the viewport and forces the page to stop scrolling right there.<\/p>\n

scroll-padding<\/code> is an optional property for any scroll-snapping container. Scroll-snapping containers are defined whenever the scroll-snap-type<\/code> property is set to any value besides none<\/code>. For more information on scroll-snapping containers see the scroll-snap-type<\/code> almanac entry<\/a>.<\/p>\n

OK, so moving on to scroll-padding<\/h3>\n

scroll-padding<\/code> is used to adjust the snapping container’s optimal viewing region. This is useful if the container has elements such as a fixed header that would obscure elements inside or if the scrollable container needs some space to give the interior elements room to breathe once they’ve been “snapped” into position.<\/p>\n

A simple example would be using scroll-padding<\/code> to create some fixed spacing of 50px<\/code> at the top and left of the container:<\/p>\n

.scroll-container {\r\n  scroll-padding: 50px 0 0 50px;\r\n}<\/code><\/pre>\n
\"A
The areas in pink show the scroll-padding on the scroll-snapping container.<\/figcaption><\/figure>\n

Syntax<\/h3>\n
\/* Shorthand *\/\r\nscroll-padding: [ <length-percentage> | auto ]{1,4};\r\n\r\n\/* Longhands *\/\r\nscroll-padding-top: <length-percentage> | auto;\r\nscroll-padding-right: <length-percentage> | auto;\r\nscroll-padding-bottom: <length-percentage> | auto;\r\nscroll-padding-left: <length-percentage> | auto;\r\n\r\n\/* inline-specific and block-specific properties as well *\/\r\nscroll-padding-block: [ <length-percentage> | auto ]{1,2};\r\nscroll-padding-inline: [ <length-percentage> | auto ]{1,2};<\/code><\/pre>\n

Important note on longhands:<\/strong> Chrome does not currently support longhand-format scroll-padding<\/code> and scroll-margin<\/code> properties. Use the shorthand for maximum browser support. See this issue on the chromium bug tracker<\/a> for more details and the current status.<\/p>\n

Values<\/h3>\n

scroll-padding<\/code> accepts the following values:<\/p>\n