Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

scroll-margin-left — left-side spacing when scrolling to an element

scroll-margin-left offsets the left edge of the area used to align an element during scrolling. It does not create an ordinary layout margin; it helps leave space to the left of the target.

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

Syntax

scroll-margin-left: <length>;
/* Examples */
scroll-margin-left: 24px;
scroll-margin-left: -8px;
scroll-margin-left: 0;

A positive scroll-margin-left value extends an element’s scroll snap area leftward; a negative value moves its left edge inward. That area starts from the bounding rectangle of its transformed border box. The property does not change layout like margin-left.

It accepts a <length>, including negative values, but not percentages or auto. Its initial value is 0; it is not inherited. It targets physical left; scroll-margin-inline-start depends on writing direction.

Set it on the target element, versus scroll-padding-left on the scroll container. It also applies when scrolling to a fragment or through scrollIntoView(), without snapping enabled. Scroll limits can constrain the spacing.

The example aligns the target to the left while leaving 24px. A test in an isolated Chromium 157.0.8103.51 environment confirmed the expected result: scrollLeft=176; gap=24px.

Examples

<!doctype html>
<meta charset="utf-8">
<title>scroll-margin-left</title>
<style>
  #scroller {
    width: 300px;
    overflow-x: auto;
    direction: ltr;
    writing-mode: horizontal-tb;
  }
  .track { display: flex; width: 700px; }
  .before { flex: 0 0 200px; }
  #target {
    flex: 0 0 100px;
    height: 60px;
    background: lightblue;
    scroll-margin-left: 24px;
  }
  .after { flex: 0 0 400px; }
</style>
<div id="scroller">
  <div class="track">
    <div class="before"></div>
    <div id="target">Target</div>
    <div class="after"></div>
  </div>
</div>
<pre id="result"></pre>
<script>
  const scroller = document.getElementById('scroller');
  const target = document.getElementById('target');
  target.scrollIntoView({ behavior: 'instant', block: 'nearest', inline: 'start' });
  requestAnimationFrame(() => {
    const gap = target.getBoundingClientRect().left
      - scroller.getBoundingClientRect().left;
    document.getElementById('result').textContent =
      `scrollLeft=${scroller.scrollLeft}; gap=${gap}px`;
  });
</script>

Result

scrollLeft=176; gap=24px

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