CSS scroll-margin-inline-end Property

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

It adjusts the area used to align an element during scrolling without changing its layout spacing. The inline-end edge depends on the element's writing mode and text direction, making this property useful for scroll snapping, horizontal scrolling, and multilingual layouts.

scroll-margin-inline-end Syntax

The scroll-margin-inline-end property accepts one CSS length value or a CSS-wide keyword.

Basic Syntax

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

Available Values

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

CSS-Wide Keywords

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

Positive values expand the scroll alignment area at inline-end, while negative values contract it. Percentages and auto are invalid.

Property Values

Value Description
<length> Sets the inline-end scroll margin using a CSS length such as px, rem, or em.
0 Applies no additional inline-end scroll margin. This is the initial value.
Positive length Expands the scroll alignment area beyond the inline-end edge.
Negative length Contracts the scroll alignment area at the inline-end edge.
calc() Calculates a valid CSS length.
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-end: 40px;
}
.target {
  scroll-margin-inline-end: 3rem;
}
.target {
  scroll-margin-inline-end: 0;
}
.target {
  scroll-margin-inline-end: -5px;
}
.target {
  scroll-margin-inline-end: calc(2rem + 15px);
}

Invalid Values

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

This longhand property accepts one length value, not percentages, multiple lengths, or scrolling behavior keywords.

How It Works

The scroll-margin-inline-end property expands or contracts the scroll alignment area surrounding a target at its logical inline-end edge.

The browser can use this adjusted area when aligning the target during scroll snapping or programmatic scrolling.

Default Inline-End Scroll Margin

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

No additional inline-end scroll margin is applied.

Positive Inline-End Scroll Margin

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

The scroll alignment area extends 40 pixels beyond the target's inline-end edge.

Negative Inline-End Scroll Margin

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

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

Using Relative Units

.target {
  scroll-margin-inline-end: 3rem;
}

Relative units can help scroll offsets adapt to typography and design settings.

No Layout Changes

The property does not change an element's width, height, normal margins, or spacing between neighboring elements.

Available Scroll Range

The final scroll position depends on the available scroll range. A target near the beginning or end of a container may not reach the requested alignment.

Writing Modes and Text Direction

The logical inline-end edge depends on the element's writing mode and text direction.

Left-to-Right Horizontal Writing

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

Inline-end corresponds to the physical right edge.

Right-to-Left Horizontal Writing

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

Inline-end corresponds to the physical left edge.

Vertical Writing

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

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

Writing Mode Reference

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

Why Logical Properties Matter

Logical scroll margins allow the same CSS declaration to adapt to different writing directions without manually changing between physical left, right, top, and bottom properties.

Scroll Snapping

The scroll-margin-inline-end property can adjust the snap area of an element at its logical inline-end edge.

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: end;
  scroll-margin-inline-end: 30px;
}

In left-to-right horizontal writing, the snap area extends 30 pixels beyond the right edge of each item.

Different Margins for Individual Items

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

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

Combining With Scroll Padding

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

Scroll padding defines an inset inside the container, while scroll margin expands the target's alignment area.

Important Consideration

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

Using the scroll-margin-inline Shorthand

The scroll-margin-inline shorthand sets the logical inline-start and inline-end 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-End

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

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

Declaration Order

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

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

Important Consideration

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

Logical Versus Physical Scroll Margins

Physical scroll margins refer to fixed edges, while logical scroll margins follow writing mode and text direction.

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

Physical Right Scroll Margin

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

The scroll margin always applies to the physical right edge.

Logical Inline-End Scroll Margin

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

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

Equivalent in Left-to-Right Horizontal Writing

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

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

Important Consideration

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

scroll-margin-inline-end Versus scroll-padding-inline-end

Both properties influence inline-end scroll alignment, but they apply to different elements.

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

Target-Side Offset

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

Container-Side Offset

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

Combining Both Properties

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

Both offsets can contribute to the final inline-end alignment position.

When to Use Each Property

Use scroll-padding-inline-end for a consistent container-side inset. Use scroll-margin-inline-end when individual targets need their own inline-end alignment spacing.

scroll-margin-inline-end Example

The following example compares two horizontal scroll panels. The second panel adds a 40-pixel inline-end scroll margin to its target, leaving additional alignment space when the target is scrolled to the inline-end edge.

HTML Example

<div class="scroll-inline-end-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-End 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-end-demo {
  display: grid;
  gap: 20px;
}
.scroll-inline-end-demo .scroll-panel {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-block: 10px;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
}
.scroll-inline-end-demo .item {
  flex: 0 0 150px;
  padding: 25px 10px;
  text-align: center;
  background-color: #e2e8f0;
}
.scroll-inline-end-demo .target {
  background-color: #bfdbfe;
  border: 2px solid #2563eb;
}
.scroll-inline-end-demo .with-margin .target {
  scroll-margin-inline-end: 40px;
}
.scroll-inline-end-demo button {
  margin-top: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

JavaScript Example

document.querySelectorAll(".scroll-inline-end-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: "end",
      block: "nearest"
    });
  });
});
Browser Result

Without Scroll Margin

Item 1
Target
Item 3
Item 4

With Inline-End Scroll Margin

Item 1
Target
Item 3
Item 4

Click each button to align the target near the inline-end edge. In left-to-right horizontal writing, the second panel requests approximately 40 pixels of space to the right of the target. The final position depends on the available scroll range.

Increasing the Offset

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

The target requests a larger inline-end alignment offset.

Removing the Offset

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

The additional inline-end scroll margin is removed.

Browser Compatibility Note

The final scroll position can depend on the browser, the scrolling operation, and the available scroll range. Targets near the boundaries of a scroll container may not reach their preferred alignment.

Accessibility Considerations

Inline-end scroll margins can improve navigation by helping users see targets that would otherwise align too closely to the edge of a scroll container.

Keep Targets Visible

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

Maintain Keyboard Accessibility

Buttons and links that trigger scrolling should remain keyboard accessible and have visible focus indicators.

Consider Focus Management

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

Support Different Text 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. If 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-end: 10%;
}

Percentages are invalid. Use a CSS length value.

Using auto

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

The property does not accept auto.

Providing Multiple Values

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

This longhand property accepts only one length.

Assuming Inline-End Always Means Right

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

Expecting Layout Spacing

Scroll margin does not change the element's layout dimensions or create space between neighboring elements.

Applying the Property to the Wrong Element

Apply scroll-margin-inline-end to the target. Use scroll-padding-inline-end on the scroll container for container-side spacing.

Expecting Automatic Scroll Snapping

The property does not enable scroll snapping by itself.

Ignoring Declaration Order

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

Confusing Scroll Margin With Smooth Scrolling

Scroll margin affects alignment. The scroll-behavior property or scrolling API options control scrolling animation.

Important Considerations

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

  • 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 lengths and calculated lengths.
  • Percentages and auto are invalid.
  • The inline-end edge depends on writing mode and text direction.
  • In left-to-right horizontal writing, inline-end corresponds to the right edge.
  • In right-to-left horizontal writing, inline-end corresponds to the left edge.
  • In vertical writing, inline-end 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-start property controls the opposite inline edge.
  • The scroll-padding-inline-end property defines container-side alignment spacing.
  • Physical and logical scroll margins can affect the same underlying edge.
  • The available scroll range can limit the final alignment position.
  • Test scrolling interfaces across different writing modes, text directions, and viewport sizes.

Browser Support

The CSS scroll-margin-inline-end 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-end.

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

Specifications

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

CSS Scroll Snap Module Level 1

The specification defines logical scroll margin properties and their role in determining the scroll snap area surrounding a target.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: scroll-margin-inline-end