Scroll-padding - CSS Property

This page is also about physical property(ies):
- scroll-padding-top
Sets the top padding for the scroll window.
- scroll-padding-right
Sets the right inner margin of the scroll window.
- scroll-padding-bottom
Sets the bottom padding of the scroll window.
- scroll-padding-left
Sets the left padding of the scroll window.
And the logical properties:
- scroll-padding-block
Sets the inner margin of the scroll window, for the start and end of blocks.
- scroll-padding-block-start
Sets the inner margin of the scroll window, for the start of blocks.
- scroll-padding-block-end
Sets the inner margin of the scroll window, for the start of blocks.
- scroll-padding-inline
Sets the inner margin of the scroll window, for the start and end of lines.
- scroll-padding-inline-start
Sets the inner margin of the scroll window, for the start of lines.
- scroll-padding-inline-end
Sets the inner margin of the scroll window, for the end of lines.
scroll-padding

Summary of characteristics of the scroll-padding property

Quick description
Sets the interior margins of the scroll window.
Status
Standard
Applies to
scroll container.
Usable for
HTML
Predefined values
auto
Percentages
Calculated relative to the corresponding dimension of the scroll window.
Initial value
auto
Inherited by default
No.
Computed value: during an animation, the scroll-padding property gradually changes from one value to another.
Per grammar: serialization in the order of syntax.
W3C Module
CSS Scroll Snap Module
Document status: CR (Candidate Recommendation)

Syntax diagram of scroll-padding.

scroll-padding - Syntax DiagramSyntax diagram of the scroll-padding CSS property. Sets the inner scroll margins. auto auto length | % length | % {1,4} {1,4}scroll-padding:;scroll-padding:;
Syntax diagram of the scroll-padding property.
The links in the diagram provide more details about the values.
Download the diagram in SVG.

Description of the scroll-padding property.

The property scroll-padding applies to a scrolling container. It defines the inner margins of this container when it comes to scrolling. In other words, it reduces the dimensions of the display area. This can be useful when elements are positioned (see the property position) because they then appear on top of the rest of the content and hide part of it.

Here is an example. A scrollable area that has a fixed part at the top (menu) and at the bottom (footer). These two elements have a property position set to sticky: they therefore do not scroll with the text and are on top of it. In the first example, on the left, you can see that there are always one or two lines of text that have not been read yet and are still hidden by these banners. In the example on the right with scroll-padding we have solved the problem.

Menu bar

In this example, a menu bar and a footer have been positioned as sticky.

When scrolling through the content with the "Page Down" or "Page Up" keys, you will notice that there is always a line or two of content that is not visible because it is hidden by the menu bar or the footer.

This problem is very annoying for reading a long text because it prevents the use of the keyboard keys to scroll through the text.
 

Footer

No scroll padding.

Menu bar

In this second example, we find the same menu bar and the same footer.

But an inner scrolling margin has been set: by scrolling the content with the "Page Down" or "Page Up" keys, you will notice that the content is displayed each time on the continuation of the text, without any line being hidden.

Reading a long text is easier because using the keyboard keys is effective again.

Some browsers repeat the last line of the previous page to display it again at the top of the next page.
 

Footer

Scrolling padding have been set withscroll-padding:30px;

In other words, the inner scrolling padding reduce the size of the scrolling window, as shown in the diagrams below. A comparable mechanism is found for horizontal scrolling.

Scroll-padding to zero
No inner scrolling padding.
With scroll-padding different from zero
With inner scrolling padding
in the vertical direction.

Also see the scroll-margin property and our explanations on scrolling with snap points (Scroll Snap), a precise mechanism for managing scrolling based on content: scrolling with snaps.

The property scroll-padding is a shorthand property for the four physical properties below:

  • scroll-padding-top: top scroll padding.
  • scroll-padding-right: right scroll padding.
  • scroll-padding-bottom: bottom scroll padding.
  • scroll-padding-left: left scroll padding.


Also see the following properties:

Overflow management, when the content is too large for the dimensions imposed on the element.
Defines the main characteristics of a scroll snap. To apply to a scrolling container.
Defines the alignment of the elements used as snaps in relation to the display window (scroll Snap technique).
Allows you to force scrolling to stop on certain elements (Scroll-Snap).
Defines the scroll margins of the scroll window in the context Scroll Snap.

Language support.

If the text is not in a Latin language, it is recommended to use the following logical properties instead, which adapt to the writing style of the language used.

  • scroll-padding-block-start: corresponds to the top scroll padding for Latin languages.
  • scroll-padding-block-end: the bottom scroll padding for Latin languages.
  • scroll-padding-inline-start: the left scroll margin for Latin languages.
  • scroll-padding-inline-end: the right scroll margin for Latin languages.

As well as the two shorthand properties scroll-padding-block and scroll-padding-inline which allow you to define in a single declaration the values for start and for end.

scroll-padding-top
scroll-padding-left
The direction and writing mode of this text adapt to the chosen language.
scroll-padding-right
scroll-padding-bottom

Values for scroll-padding.

  • scroll-padding: auto;

    The browser is free to choose whether or not to apply scrolling margins. Most often, the auto value corresponds to the absence of scrolling padding, but it is possible that browsers automatically apply padding corresponding to positioned elements likely to obscure the content.

  • scroll-padding: 20px; scroll-padding: 20px 10px; scroll-padding: 20px 10px 15px; scroll-padding: 20px 10px 15px 15px;

    One to four values are accepted. They must be followed by one of CSS dimension units. If they are percentages, they will be evaluated relative to the corresponding dimension of the scroll window (height or width). The total percentage in a given direction must therefore be less than 50%, otherwise no further scrolling is possible.

    Here is how the values are assigned based on their number:

    • If only one value is specified, it applies equally to all four scroll margins.
    • If two values are specified, the first defines the top and bottom margins, and the second value defines the left and right margins.
    • When three values are specified, they define respectively the top margin, the left and right margins, and the bottom margin.
    • Finally, if all four values are specified, they each define margins, in the following order: top margin, right margin, bottom margin, left margin.
    A single value for scroll-padding
    A single value.
    Two values for scroll-padding
    Two values.
    Three values for scroll-padding
    Three values.
    Four values for scroll-padding
    Four values.
  • scroll-padding: initial; (auto) scroll-padding: inherit; scroll-padding: revert; scroll-padding: revertLayer; scroll-padding: unset;

    Common values ​​are presented on these pages: initial, inherit, revert, revert-layer, unset.

Animation of the scroll-padding property.

The animation of scroll-padding is possible but not very spectacular. Its effect is only visible when interacting with the scroll bar. There is therefore no continuous effect that would be visible at all times.

🐘 🐄 🐌 🐬 🐊 🐁 🦘

Access the scroll-padding property via a program

With Javascript, change the value of scroll-padding.

In JavaScript, it is possible to modify the inner scrolling margins by acting on the property scroll-padding. The language offers a syntax with the typical CSS notation, in kebab-case, and another syntax with the notation in camel-case.

Javascript
let el = document.getElementById('id'); el.style['scroll-padding'] = '1vw'; // or let el = document.getElementById('id'); el.style.scrollPadding = '1vw';

With Javascript, read the value of scroll-padding.

The property must have been applied directly to the element itself via its style attribute, and not through a CSS selector. This code is the mirror image of the previous one.

Javascript
let el = document.getElementById('id'); let value = el.style['scroll-padding']; // or let el = document.getElementById('id'); let value = el.style.scrollPadding;

With Javascript, read the computed value of scroll-padding.

The computed value is the one that results from the evaluation of the relative units (except the percentage) and the possible consideration of inherited values. If no value has been assigned to the element, either directly or by inheritance, the calculated value is equal to the initial value (auto in the case of scroll-padding).

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('scroll-padding');

With JQuery, change the value of scroll-padding.

With JQuery it is also possible to modify the size of the inner scrolling margins. The syntaxes are generally shorter than those of Javascript.

JQuery

$('#id').css('scroll-padding', '1vw');
// or
$('#id').css('scrollPadding', '1vw');

With JQuery, read the computed value of scroll-padding.

JQuery
let value = $('#id').css('scroll-padding');

Other code examples.

JavaScript and JQuery codes are provided on the page Javascript and CSS: adding a style sheet, adding or removing classes, etc.

Test it yourself.

The buttons below apply the entered value to the property scroll-padding and then display either the value as it was applied, or the computed value. This second option allows you to see how the value of scroll-padding is stored (serialized). It is particularly noticeable that percentages are correctly stored as percentages (see the chapter on inheritance in CSS). All other units are converted to pixels.

Simulator.

In this example, there are no fixed banners. The property scroll-padding is used only for aesthetic reasons: to avoid sticking the elements to the edge of the scrolling container.

scroll-padding :

😴

🥶

🤖

🤡

🤐

🤓

🤒

Browsers compatibility with scroll-padding.

The property scroll-padding is well recognized by all major browsers.

Column 1
Support for the properties scroll-padding-... to reserve space on one side of the scrolling container, for example to make room for a non-scrolling element.
1
scroll-padding
property
Estimated overall support.
95%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

UC Browser pour Androïd

Opéra Mobile

QQ Browser

Baidu Browser

Opéra

Samsung Internet

Firefox pour Androïd

Edge

Firefox

Chrome pour Androïd

Androïd Brower

Safari

Safari sur IOS

Chrome

KaiOS Browser

Opéra mini

Historic of the scroll-padding property.

  • CSS Scroll Snap Module - Level 1

    This specification module defines the features regarding scrolling with snap positions. In other words, content-aligned scrolling, to prevent, for example, an image from being cut off at the top or bottom of its container.

    Regarding scroll-padding. First introduction to the scroll-padding property.
    WD
    March 26, 2015
    Working Draft.
    CR
    October 20, 2016
    Candidate Recommendation.
    PR
    REC

See also, regarding scrolls with snags.

Scrolling with snapping is described in the CSS Scroll Snap Module. The property scroll-padding and its derivatives, as well as all those related to the subject, are also present in this module.

Properties:

scroll-margin
Defines the scroll margins of the scroll window in the context Scroll Snap.
scroll-margin-block
Sets the scroll window margins for the start and end of blocks.
scroll-margin-block-end
Sets the scroll window margins for end of blocks.
scroll-margin-block-start
Sets the scroll window margins for the start of blocks.
scroll-margin-bottom
Sets the margins at the bottom of the scroll window in the context of scrolling with snapping.
scroll-margin-inline
Sets the scroll window margins for the start and end of lines.
scroll-margin-inline-end
Sets the scroll window margins for the end of lines.
scroll-margin-inline-start
Sets the scroll window margins for the start of lines.
scroll-margin-left
Sets the margins at the top of the scroll window in the context of scrolling with snapping.
scroll-margin-right
Sets the right margins of the scroll window in the context of scroll snapping.
scroll-margin-top
Sets the top margins of the scroll window in the context of scroll snapping.
Scroll-padding
Sets the interior margins of the scroll window.
Scroll-padding-block
Sets the inner margin of the scroll window, for the start and end of blocks.
Scroll-padding-block-end
Sets the inner margin of the scroll window, for the start of blocks.
Scroll-padding-block-start
Sets the inner margin of the scroll window, for the start of blocks.
Scroll-padding-bottom
Sets the bottom padding of the scroll window.
Scroll-padding-inline
Sets the inner margin of the scroll window, for the start and end of lines.
Scroll-padding-inline-end
Sets the inner margin of the scroll window, for the end of lines.
Scroll-padding-inline-start
Sets the inner margin of the scroll window, for the start of lines.
Scroll-padding-left
Sets the left padding of the scroll window.
Scroll-padding-right
Sets the right inner margin of the scroll window.
Scroll-padding-top
Sets the top padding for the scroll window.
scroll-snap-align
Defines the alignment of the elements used as snaps in relation to the display window (scroll Snap technique).
scroll-snap-stop
Allows you to force scrolling to stop on certain elements (Scroll-Snap).
scroll-snap-type
Defines the main characteristics of a scroll snap. To apply to a scrolling container.