CSS scroll-margin-inline Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Logical Properties

What You’ll Learn

The scroll-margin-inline property sets scroll offsets on the inline axis. It is the logical companion to left/right scroll margins and works especially well with horizontal scroll snapping and carousels.

01

inline

Horizontal flow.

02

start

Inline-start.

03

end

Inline-end.

04

snap

x-axis snap.

05

carousel

Side scroll.

06

logical

RTL safe.

Introduction

The scroll-margin-inline property in CSS is used to define the margin on the inline start and inline end edges of an element when it is scrolled into view.

This property is particularly useful when working with horizontal scroll snapping, allowing you to adjust the scroll offset for elements along the inline axis, which varies based on the writing mode and direction of the document.

Definition and Usage

scroll-margin-inline is a logical shorthand for scroll-margin-inline-start and scroll-margin-inline-end. Apply it to the scroll target element inside a horizontally scrollable container.

In standard LTR horizontal writing mode, inline-start maps to the left and inline-end maps to the right. The property also works with anchor links and scrollIntoView() inside overflow containers.

💡
Beginner Tip

On a normal English webpage, think of scroll-margin-inline as “left and right scroll offset” that follows text direction.

📝 Syntax

The syntax for the scroll-margin-inline property is straightforward. You can specify a single value or two values for the inline start and inline end margins.

syntax.css
element {
  scroll-margin-inline: value;
}

element {
  scroll-margin-inline: inline-start-value inline-end-value;
}

Basic Example

scroll-margin-inline.css
.item {
  scroll-margin-inline: 20px;
}

Longhand Properties

  • scroll-margin-inline-start — offset at the inline-start edge
  • scroll-margin-inline-end — offset at the inline-end edge

Syntax Rules

  • One value sets both inline-start and inline-end equally.
  • Two values set inline-start first, then inline-end.
  • Lengths and percentages are valid.
  • Works with scroll-snap-type: x mandatory and similar horizontal snap rules.

🎯 Default Value

The default value of the scroll-margin-inline property is 0, which means there is no additional margin applied when the element is scrolled into view.

⚡ Quick Reference

QuestionAnswer
Default value0
LTR horizontal writingUsually left and right scroll offset
Shorthand forscroll-margin-inline-start + scroll-margin-inline-end
Accepted valuesLengths and percentages
InheritedNo
AnimatableNo

💎 Property Values

ValueExampleDescription
lengthscroll-margin-inline: 20px;A length that defines the margin. If one value is given, it applies to both inline-start and inline-end.
two valuesscroll-margin-inline: 32px 12px;The first value applies to inline-start; the second applies to inline-end.
percentagescroll-margin-inline: 10%;A percentage relative to the element’s inline size.
20px 32px 12px 10%

When to Use scroll-margin-inline

scroll-margin-inline is the right choice when inline-axis scroll offsets should follow logical layout:

  • Horizontal carousels — Keep snapped cards away from container side edges.
  • Scroll snapping on the x-axis — Fine-tune where items land when swiping sideways.
  • RTL layouts — Prefer logical inline margins over hard-coded left/right rules.
  • Overflow panels — Improve targets inside horizontally scrollable toolbars or tabs.

For vertical offsets, use scroll-margin-block instead.

👀 Live Preview

Scroll sideways in the demo. Each item uses scroll-snap-align: center and scroll-margin-inline: 0.75rem.

1
2
3
4
5

Inline-axis margin creates side breathing room when each item snaps into view.

Examples Gallery

Start with the reference horizontal snap row, set different inline-start and inline-end values, try a carousel panel, and use the scroll-margin-inline-start longhand on the first slide.

📜 Inline-Axis Offsets

Control scroll stop position on the inline axis — matching the reference example.

Example 2 — Different inline-start and inline-end values

Use two values when the sides need different offsets: scroll-margin-inline: 32px 12px;.

two-values.css
.card {
  scroll-margin-inline: 32px 12px;
}
Try It Yourself

How It Works

The first value applies to inline-start; the second applies to inline-end.

🗃 Carousels & Longhands

Use inline offsets in carousel panels and fine-tune only the inline-start side when needed.

Example 3 — Carousel-style panel

Combine overflow-x: auto with scroll-margin-inline on each slide.

carousel.css
.slide {
  scroll-snap-align: center;
  scroll-margin-inline: 16px;
}
Try It Yourself

How It Works

The scroll container defines horizontal snapping; each child defines its own inline-axis stop offset.

Example 4 — scroll-margin-inline-start

When only the inline-start side needs offset, use the longhand: scroll-margin-inline-start: 24px;.

inline-start.css
#slide-1 {
  scroll-margin-inline-start: 24px;
}
Try It Yourself

How It Works

Longhands let you tune one logical side without affecting inline-end.

scroll-margin-inline vs physical sides

scroll-margin is the physical shorthand for all four sides. scroll-margin-inline targets only the inline axis and is safer for multilingual and RTL layouts.

Pair horizontal snapping with scroll-margin-block when a layout also needs vertical scroll offsets.

logical-vs-physical.css
/* Physical sides */
.physical { scroll-margin-left: 20px; scroll-margin-right: 20px; }

/* Logical inline shorthand */
.logical { scroll-margin-inline: 20px; }

🧠 How scroll-margin-inline Works

1

Inline axis is determined

Writing mode and direction decide which sides are inline-start and inline-end.

Logical
2

Scroll target area grows

scroll-margin-inline adds offset on both inline edges of the snap area.

Offset
3

Browser scrolls into place

Horizontal snap, anchor links, or scrollIntoView() use the expanded area.

Position
=

Polished sideways scrolling

Carousel items land with comfortable side spacing when snapped.

Browser Compatibility

The scroll-margin-inline property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.

Logical scroll margins · Modern support

Reliable scroll-margin-inline support

Current Chrome, Firefox, Safari, Edge, and Opera support logical scroll-margin properties.

97% Modern browser support
Google Chrome 69+ · Desktop & Mobile
Full support
Mozilla Firefox 68+ · Desktop & Mobile
Full support
Apple Safari 14.1+ · macOS & iOS
Full support
Microsoft Edge 79+ · Chromium
Full support
Opera 56+ · Modern versions
Full support

Testing tip

Test horizontal snap carousels on iOS Safari and in RTL mode to confirm inline-start/end behavior.

scroll-margin-inline property 97% supported

Bottom line: scroll-margin-inline is widely supported for horizontal scroll snap and in-page navigation in modern browsers.

Conclusion

The scroll-margin-inline property is a useful tool for adjusting the scroll snapping behavior of elements within a scroll container.

By customizing the margin on the inline axis, you can create a more refined and visually appealing scrolling experience. Experiment with different values to see how this property can improve the layout and usability of your web projects.

💡 Best Practices

✅ Do

  • Prefer logical scroll-margin-inline for carousels and RTL layouts
  • Pair with scroll-snap-type: x mandatory on the container
  • Use two values when inline-start and inline-end need different spacing
  • Apply offsets on snap children, not the scroll container
  • Test sideways scrolling on touch devices

❌ Don’t

  • Confuse scroll-margin-inline with regular margin-inline
  • Hard-code left/right when logical inline properties are enough
  • Forget vertical offsets when items also need block-axis space
  • Assume inline-start always equals left in every writing mode
  • Use huge percentage values without testing narrow containers

Key Takeaways

Knowledge Unlocked

Five things to remember about scroll-margin-inline

Use these points when offsetting inline-axis scroll targets.

5
Core concepts
02

inline axis

Side flow.

Axis
03

20px

Both sides.

Pattern
04

x snap

Carousels.

Use case
🔄 05

longhands

inline-start.

Detail

❓ Frequently Asked Questions

scroll-margin-inline sets scroll offset on the inline axis — inline-start and inline-end — when an element is scrolled into view. In horizontal left-to-right writing mode, that usually means left and right.
scroll-margin-inline is a logical shorthand that follows the document inline direction. scroll-margin-left and scroll-margin-right are physical sides.
They are logical directions along the inline axis. In LTR horizontal writing, inline-start is left and inline-end is right. In RTL, they swap.
The default value is 0, meaning no extra inline-axis offset is applied to the scroll target.
Use it for horizontal scroll snapping, carousels, sideways panels, and any scroll target that needs left/right breathing room in logical layouts.

Practice in the Live Editor

Open the HTML editor and try scroll-margin-inline: 20px with horizontal scroll snap.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful