CSS scroll-margin-inline-start Property

The CSS scroll-margin-inline-start property sets the scroll margin at the logical inline-start edge of an element.

It adjusts the area used to align an element during scrolling without changing its normal layout spacing. Because inline-start depends on writing mode and text direction, the property is useful for scroll snapping, horizontal navigation, and interfaces that support different languages.

scroll-margin-inline-start Syntax

The scroll-margin-inline-start property accepts a single CSS length value or a CSS-wide keyword.

Basic Syntax

selector {
  scroll-margin-inline-start: 20px;
}

Available Values

.target {
  scroll-margin-inline-start: 0;
}
.target {
  scroll-margin-inline-start: 20px;
}
.target {
  scroll-margin-inline-start: 2rem;
}
.target {
  scroll-margin-inline-start: 1.5em;
}
.target {
  scroll-margin-inline-start: -10px;
}
.target {
  scroll-margin-inline-start: calc(1rem + 10px);
}

CSS-Wide Keywords

.target {
  scroll-margin-inline-start: initial;
}
.target {
  scroll-margin-inline-start: inherit;
}
.target {
  scroll-margin-inline-start: unset;
}
.target {
  scroll-margin-inline-start: revert;
}
.target {
  scroll-margin-inline-start: revert-layer;
}

Positive lengths expand the target's scroll alignment area at inline-start. Negative lengths contract it. Percentages and auto are invalid.

Property Values

Value Description
<length> Sets the inline-start scroll margin using a CSS length such as px, rem, or em.
0 Applies no additional inline-start scroll margin. This is the initial value.
Positive length Expands the scroll alignment area beyond the inline-start edge.
Negative length Contracts the scroll alignment area at the inline-start edge.
calc() Calculates a valid length using a CSS mathematical expression.
initial Resets the property to 0.
inherit Uses the computed value from the parent element.
unset Resets the property to 0 because it is not inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value 0
Inherited No
Applies to All elements
Computed value Absolute length
Animation type By computed value, as a length
Percentages Not accepted

Valid Values

.target {
  scroll-margin-inline-start: 40px;
}
.target {
  scroll-margin-inline-start: 3rem;
}
.target {
  scroll-margin-inline-start: 0;
}
.target {
  scroll-margin-inline-start: -5px;
}
.target {
  scroll-margin-inline-start: calc(2rem + 15px);
}

Invalid Values

.target {
  scroll-margin-inline-start: auto;
}
.target {
  scroll-margin-inline-start: 10%;
}
.target {
  scroll-margin-inline-start: 10px 20px;
}
.target {
  scroll-margin-inline-start: smooth;
}
.target {
  scroll-margin-inline-start: 2s;
}

This longhand property accepts one CSS length, not percentages, multiple values, or scrolling behavior keywords.

How It Works

The scroll-margin-inline-start property adjusts the scroll alignment area surrounding an element at its logical inline-start edge.

The browser can use this adjusted area when determining where to position a target during scroll snapping or programmatic scrolling.

Default Inline-Start Scroll Margin

.target {
  scroll-margin-inline-start: 0;
}

The target receives no additional inline-start scroll margin.

Positive Inline-Start Scroll Margin

.target {
  scroll-margin-inline-start: 40px;
}

The scroll alignment area extends 40 pixels beyond the inline-start edge.

Negative Inline-Start Scroll Margin

.target {
  scroll-margin-inline-start: -10px;
}

The scroll alignment area contracts by 10 pixels at inline-start.

Using Relative Lengths

.target {
  scroll-margin-inline-start: 2rem;
}

Relative units allow scroll offsets to scale with typography settings.

Layout Space Is Unchanged

Unlike margin-inline-start, this property does not add normal layout space or push neighboring elements apart.

Available Scroll Range

A scroll target near the beginning or end of a container may not reach its requested alignment because the container cannot scroll beyond its available range.

Writing Modes and Text Direction

The inline-start edge follows the writing mode and text direction rather than a fixed physical side.

Left-to-Right Horizontal Writing

.target {
  writing-mode: horizontal-tb;
  direction: ltr;
  scroll-margin-inline-start: 40px;
}

Inline-start corresponds to the physical left edge.

Right-to-Left Horizontal Writing

.target {
  writing-mode: horizontal-tb;
  direction: rtl;
  scroll-margin-inline-start: 40px;
}

Inline-start corresponds to the physical right edge.

Vertical Writing

.target {
  writing-mode: vertical-rl;
  direction: ltr;
  scroll-margin-inline-start: 40px;
}

In vertical writing with left-to-right inline progression, inline-start corresponds to the physical top edge.

Writing Mode Reference

Writing Mode and Direction Inline-Start Edge
horizontal-tb, ltr Left
horizontal-tb, rtl Right
vertical-rl, ltr Top
vertical-rl, rtl Bottom
vertical-lr, ltr Top
vertical-lr, rtl Bottom

Why Logical Properties Matter

Logical scroll margins adapt to different writing directions without requiring separate physical left, right, top, or bottom declarations.

Scroll Snapping

The scroll-margin-inline-start property is useful when scroll targets align at the logical inline-start edge of a scroll container.

Horizontal Scroll Snap Example

.gallery {
  display: flex;
  gap: 20px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}
.gallery .item {
  flex: 0 0 200px;
  scroll-snap-align: start;
  scroll-margin-inline-start: 30px;
}

In left-to-right horizontal writing, the snap area extends 30 pixels to the left of each item, affecting its start alignment.

Different Offsets for Individual Targets

.gallery .item {
  scroll-margin-inline-start: 20px;
}
.gallery .item.featured {
  scroll-margin-inline-start: 60px;
}

The featured item receives a larger inline-start scroll margin.

Combining With Scroll Padding

.gallery {
  scroll-padding-inline-start: 20px;
}
.gallery .item {
  scroll-margin-inline-start: 30px;
}

Scroll padding defines a container-side inset, while scroll margin adjusts the alignment area around each target.

Important Consideration

The property does not enable scroll snapping. The container must define scroll-snap-type, and its targets must define an appropriate scroll-snap-align value.

Using the scroll-margin-inline Shorthand

The scroll-margin-inline shorthand controls both logical inline scroll margins.

Two-Value Shorthand

.target {
  scroll-margin-inline: 20px 40px;
}

The first value sets inline-start to 20 pixels, and the second sets inline-end to 40 pixels.

Equivalent Longhand Declarations

.target {
  scroll-margin-inline-start: 20px;
  scroll-margin-inline-end: 40px;
}

One-Value Shorthand

.target {
  scroll-margin-inline: 30px;
}

Both inline edges receive 30 pixels of scroll margin.

Overriding Inline-Start

.target {
  scroll-margin-inline: 20px;
  scroll-margin-inline-start: 60px;
}

Inline-start becomes 60 pixels, while inline-end remains 20 pixels.

Declaration Order

.target {
  scroll-margin-inline-start: 60px;
  scroll-margin-inline: 20px;
}

The later shorthand resets both inline scroll margins to 20 pixels.

Important Consideration

Use the longhand when only inline-start needs an adjustment. Use the shorthand when both inline edges need related values.

Logical Versus Physical Scroll Margins

Physical scroll margins refer to fixed sides of an element. Logical scroll margins follow the writing mode and text direction.

Property Edge
scroll-margin-inline-start Logical inline-start edge
scroll-margin-left Physical left edge
scroll-margin-right Physical right edge
scroll-margin-top Physical top edge
scroll-margin-bottom Physical bottom edge

Physical Left Scroll Margin

.target {
  scroll-margin-left: 40px;
}

The margin always applies to the physical left edge.

Logical Inline-Start Scroll Margin

.target {
  scroll-margin-inline-start: 40px;
}

The margin follows inline-start, which may correspond to the left, right, top, or bottom edge.

Equivalent in Left-to-Right Horizontal Writing

.target {
  writing-mode: horizontal-tb;
  direction: ltr;
  scroll-margin-inline-start: 40px;
}

In this writing mode, the declaration corresponds to scroll-margin-left: 40px.

Important Consideration

Physical and logical scroll margin declarations can affect the same underlying edge. Normal CSS cascade rules determine which value applies when declarations overlap.

Scroll Margin Versus Scroll Padding

The scroll-margin-inline-start and scroll-padding-inline-start properties both influence inline-start alignment, but they apply to different elements.

Property Applied To Purpose
scroll-margin-inline-start Scroll target Expands or contracts the target's alignment area at inline-start.
scroll-padding-inline-start Scroll container Defines an inset at the container's logical inline-start edge.

Target-Side Offset

.item {
  scroll-margin-inline-start: 40px;
}

Container-Side Offset

.gallery {
  scroll-padding-inline-start: 40px;
}

Combining Both Properties

.gallery {
  scroll-padding-inline-start: 20px;
}
.gallery .item {
  scroll-margin-inline-start: 30px;
}

Both offsets can contribute to the final position of an inline-start-aligned target.

When to Use Each Property

Use scroll-padding-inline-start when the container needs a consistent alignment inset. Use scroll-margin-inline-start when individual targets require additional spacing.

scroll-margin-inline-start Example

This example compares two horizontal scroll panels. The second panel applies a 40-pixel inline-start scroll margin to its target, leaving additional space before the target when it is aligned at the inline-start edge.

HTML Example

<div class="scroll-inline-start-demo">
  <div class="scroll-example">
    <h3>Without Scroll Margin</h3>
    <div class="scroll-panel">
      <div class="item">Item 1</div>
      <div class="item target">Target</div>
      <div class="item">Item 3</div>
      <div class="item">Item 4</div>
    </div>
    <button type="button">Scroll to Target</button>
  </div>
  <div class="scroll-example with-margin">
    <h3>With Inline-Start Scroll Margin</h3>
    <div class="scroll-panel">
      <div class="item">Item 1</div>
      <div class="item target">Target</div>
      <div class="item">Item 3</div>
      <div class="item">Item 4</div>
    </div>
    <button type="button">Scroll to Target</button>
  </div>
</div>

CSS Example

.scroll-inline-start-demo {
  display: grid;
  gap: 20px;
}
.scroll-inline-start-demo .scroll-panel {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-block: 10px;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
}
.scroll-inline-start-demo .item {
  flex: 0 0 150px;
  padding: 25px 10px;
  text-align: center;
  background-color: #e2e8f0;
}
.scroll-inline-start-demo .target {
  background-color: #bfdbfe;
  border: 2px solid #2563eb;
}
.scroll-inline-start-demo .with-margin .target {
  scroll-margin-inline-start: 40px;
}
.scroll-inline-start-demo button {
  margin-top: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

JavaScript Example

document.querySelectorAll(".scroll-inline-start-demo .scroll-example").forEach((example) => {
  const button = example.querySelector("button");
  const target = example.querySelector(".target");
  button.addEventListener("click", () => {
    target.scrollIntoView({
      behavior: window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "instant" : "smooth",
      inline: "start",
      block: "nearest"
    });
  });
});
Browser Result

Without Scroll Margin

Item 1
Target
Item 3
Item 4

With Inline-Start Scroll Margin

Item 1
Target
Item 3
Item 4

Click the button beneath each panel. In left-to-right horizontal writing, the second panel requests approximately 40 pixels of space to the left of its target. The exact alignment depends on the available scroll range.

Increasing the Inline-Start Offset

.scroll-inline-start-demo .with-margin .target {
  scroll-margin-inline-start: 70px;
}

The target requests a larger inline-start alignment offset.

Removing the Offset

.scroll-inline-start-demo .with-margin .target {
  scroll-margin-inline-start: 0;
}

The additional inline-start scroll margin is removed.

Browser Compatibility Note

The final scroll position may vary depending on browser behavior, scrolling direction, and available scroll range. Targets near the boundaries of a scroll container may not reach their requested alignment.

Accessibility Considerations

Inline-start scroll margins can help users locate content in horizontally or vertically scrolling interfaces by providing additional space before a target.

Keep Scroll Targets Visible

Use appropriate offsets when sticky or overlaid controls could obscure content at the inline-start edge.

Maintain Keyboard Accessibility

Scrolling controls should remain keyboard accessible and provide visible focus indicators.

Consider Focus Management

Scrolling an element into view does not necessarily move keyboard focus. Scripted navigation may require additional focus handling.

Support Different Writing Directions

Logical scroll margins adapt to left-to-right, right-to-left, and vertical writing modes.

Respect Reduced Motion Preferences

The property does not animate scrolling. When smooth scrolling is used alongside it, respect prefers-reduced-motion.

Test Responsive Layouts

Verify that scroll offsets remain useful at different viewport widths, zoom levels, and writing directions.

Common Mistakes

Using Percentages

.target {
  scroll-margin-inline-start: 10%;
}

Percentages are invalid. Use a CSS length.

Using auto

.target {
  scroll-margin-inline-start: auto;
}

The property does not accept auto.

Providing Multiple Values

.target {
  scroll-margin-inline-start: 10px 20px;
}

This longhand property accepts only one length value.

Assuming Inline-Start Always Means Left

Inline-start corresponds to the left edge in left-to-right horizontal writing, but it can refer to the right, top, or bottom edge in other writing modes.

Expecting Layout Spacing

Scroll margins do not add normal layout space or change the dimensions of an element.

Applying the Property to the Wrong Element

Apply scroll-margin-inline-start to the target. Use scroll-padding-inline-start on the scroll container for a container-side inset.

Expecting Automatic Scroll Snapping

The property adjusts scroll alignment but does not enable scroll snapping by itself.

Ignoring Declaration Order

A later scroll-margin-inline shorthand can override an earlier inline-start longhand declaration.

Confusing Scroll Margin With Smooth Scrolling

Scroll margin affects alignment, while scroll-behavior or scrolling API options control animation.

Important Considerations

Keep the following points in mind when using scroll-margin-inline-start:

  • It is a logical scroll margin longhand property.
  • Its initial value is 0, and it is not inherited.
  • It accepts one CSS length, including negative and calculated lengths.
  • Percentages and auto are invalid.
  • Inline-start depends on writing mode and text direction.
  • In left-to-right horizontal writing, inline-start corresponds to the left edge.
  • In right-to-left horizontal writing, inline-start corresponds to the right edge.
  • In vertical writing, inline-start can correspond to the top or bottom edge.
  • It changes scroll alignment without changing normal layout spacing.
  • It can influence scroll snapping and programmatic scrolling.
  • It does not create a scroll container, enable scroll snapping, or control smooth scrolling.
  • The scroll-margin-inline shorthand sets both logical inline scroll margins.
  • The scroll-margin-inline-end property controls the opposite inline edge.
  • The scroll-padding-inline-start property provides container-side alignment spacing.
  • Physical and logical scroll margins can affect the same underlying edge.
  • Available scroll range can limit the final alignment position.
  • Test scrolling interfaces across different writing modes, directions, and viewport sizes.

Browser Support

The CSS scroll-margin-inline-start property is Baseline Widely available and is supported in current versions of major browsers.

Older browsers may have limited support for logical scroll margin properties. The visible effect also depends on the scrolling operation and available scroll range.

For current compatibility information, visit Can I Use? and search for scroll-margin-inline-start.

When unsupported, scrolling generally remains functional, but the additional inline-start alignment offset may not be applied.

Specifications

The scroll-margin-inline-start property is defined in CSS Scroll Snap Module Level 1.

CSS Scroll Snap Module Level 1

The specification defines logical scroll margin properties and how they adjust the scroll snap area surrounding a target.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: scroll-margin-inline-start