Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

scroll-padding-top — top inset for the scrolling viewing region

scroll-padding-top insets the top edge of the scrolling target region without adding layout spacing.

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

Syntax

scroll-padding-top: auto | <length-percentage [0,∞]>;

scroll-padding-top sets an inward top offset for a scroll container's optimal viewing region. Unlike padding-top, it does not change layout and also works without scroll snapping.

It accepts auto or a nonnegative length or percentage of the scrollport height. The initial auto lets the browser choose, usually 0px. It is not inherited.

top always refers to the physical top edge. scroll-padding-block-start follows the block-start edge: top in writing-mode: horizontal-tb, right in writing-mode: vertical-rl, and left in writing-mode: vertical-lr. Set scroll-padding-top on the container, but scroll-margin-top on the target. For document scrolling, use html, not body. Available scroll range limits whether the offset can be achieved.

Examples

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

Result

After clicking Scroll: Target is 40 CSS px below the top of the scrollport; scroller.scrollTop is 160.

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