Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

scroll-padding — scrolling-region insets

scroll-padding defines a preferred viewing region inside a scroll container without changing element layout.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

scroll-padding: [ auto | <length-percentage [0,∞]> ]{1,4};

scroll-padding sets inward offsets for the region used when scrolling elements into view; it works without scroll snapping. Unlike padding, it creates no layout space. Apply it to the container, and scroll-margin to the target.

It accepts 1–4 values like padding: all sides; vertical/horizontal; top/horizontal/bottom; top/right/bottom/left. Lengths and percentages must be nonnegative. Percentages use the corresponding scrollport dimension. Initial auto lets the browser choose, usually zero. The property is not inherited.

For document scrolling, set it on html, not body. It neither enables snapping nor adds scrollable range; scroll limits can prevent the requested alignment.

Examples

<!doctype html>
<meta charset="utf-8">
<title>scroll-padding</title>
<style>
  #scroller {
    height: 160px;
    overflow: auto;
    scroll-padding: 40px 0 0;
  }
  .space { height: 240px; }
  #target { height: 40px; background: gold; }
</style>
<button id="go">Scroll to target</button>
<div id="scroller">
  <div class="space"></div>
  <div id="target">Target</div>
  <div class="space"></div>
</div>
<script>
  document.querySelector('#go').addEventListener('click', () => {
    document.querySelector('#target').scrollIntoView({
      block: 'start', behavior: 'instant'
    });
  });
</script>

Result

After clicking “Scroll to target”, Target is positioned 40 CSS pixels below the top of the scrollport; #scroller.scrollTop is 200.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources