{"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":"
A simple example would be using Important note on longhands:<\/strong> Chrome does not currently support longhand-format See the Pen scroll-padding example This browser support data is from Caniuse<\/a>, which has more detail. A number indicates that browser supports the feature at that version and up.<\/p><\/div>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
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
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
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
\n
auto<\/code> leaves the padding to be determined by the browser\/user-agent. Generally, this means a value of 0px, but can be non-zero if the user-agent decides another value is more appropriate.<\/li>\n
<length-percentage><\/code> is written similar to
padding<\/code> and other properties where the value can be defined with units (
px<\/code>,
em<\/code>,
vh<\/code>, etc.) or as a percentage of the container itself.<\/li>\n<\/ul>\n
Example<\/h3>\n
\n<\/a> by CSS-Tricks (@css-tricks<\/a>) on CodePen<\/a>.<\/p>\nBrowser Support<\/h3>\n
Desktop<\/h4>