Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

scroll-margin-block — logical scroll margin

scroll-margin-block sets outsets around a scrolling target at the start and end of the block axis without changing element layout.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate

Syntax

scroll-margin-block: <length>{1,2};

scroll-margin-block is shorthand for scroll-margin-block-start and scroll-margin-block-end. One length sets both ends; two specify start then end. Both initially equal 0; the property is not inherited. Percentages and auto are invalid; negative lengths are allowed.

The axis follows writing-mode: with horizontal-tb, it means top and bottom. The property changes the area used for snapping and scrolling a target into view, not layout spacing like margin. Unlike scroll-padding-block, it belongs on the target, not the container.

The example uses scrollIntoView() without snapping. Alignment start uses 24px; 8px concerns the end. Clicking the button displays scrollTop: 216.

Examples

<!doctype html>
<meta charset="utf-8">
<title>scroll-margin-block</title>
<style>
  #scroller {
    height: 160px;
    overflow: auto;
    writing-mode: horizontal-tb;
  }
  .space { height: 240px; }
  #target {
    height: 40px;
    background: gold;
    scroll-margin-block: 24px 8px;
  }
</style>
<button type="button" id="go">Scroll</button>
<div id="scroller">
  <div class="space"></div>
  <div id="target">Target</div>
  <div class="space"></div>
</div>
<pre id="result"></pre>
<script>
  const scroller = document.querySelector('#scroller');
  const target = document.querySelector('#target');
  document.querySelector('#go').addEventListener('click', () => {
    target.scrollIntoView({ block: 'start', behavior: 'instant' });
    document.querySelector('#result').textContent =
      `scrollTop: ${scroller.scrollTop}`;
  });
</script>

Result

scrollTop: 216

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