CSS scroll-margin-left Property

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 4 Examples
Physical Properties

What You’ll Learn

The scroll-margin-left property offsets a scroll target at the left edge. It is useful when you want space between the left side of the viewport or scroll container and the element being scrolled into view.

01

left

Physical left edge.

02

offset

Scroll stop space.

03

length

px, rem, %.

04

target

On the element.

05

carousel

First slides.

06

snap

Horizontal panels.

Introduction

The scroll-margin-left property in CSS is used to set the left margin of an element when it is scrolled into view.

This property is particularly useful when you want to create space between the left edge of the viewport and the scrolled-to element, ensuring it is not flush against the edge.

Definition and Usage

Apply scroll-margin-left to the element being scrolled to — not to the scroll container itself. It works with anchor links, scrollIntoView(), focus navigation, and scroll snapping.

It is one longhand of the scroll-margin shorthand. In LTR layouts it often behaves like scroll-margin-inline-start, but it always targets the physical left edge.

💡
Beginner Tip

scroll-margin-left: 50px tells the browser to leave 50px of space to the left of the target when it becomes the scroll destination.

📝 Syntax

The syntax for the scroll-margin-left property is straightforward. You can specify a length value using units such as px, em, rem, %, and more.

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

Here, value can be any valid CSS length value.

Basic Example

scroll-margin-left.css
.target {
  scroll-margin-left: 50px;
}

Related Properties

  • scroll-margin-right — offset at the right edge
  • scroll-margin — shorthand for all four sides
  • scroll-margin-inline-start — logical inline-start offset

🎯 Default Value

The default value of the scroll-margin-left property is 0. This means there is no additional margin applied when the element is scrolled into view by default.

⚡ Quick Reference

QuestionAnswer
Default value0
LTR horizontal writingLeft scroll offset
Part ofscroll-margin shorthand
Accepted valuesLengths and percentages
InheritedNo
AnimatableNo

💎 Property Values

ValueExampleDescription
lengthscroll-margin-left: 50px;Specifies the margin as a length value in units like px, em, rem, or %. For example, 20px, 2em, 10%.
percentagescroll-margin-left: 10%;A percentage of the containing block’s inline size, such as 10%.
50px 2rem 10%

When to Use scroll-margin-left

scroll-margin-left helps when the left side of a target needs breathing room:

  • First carousel card — Keep the opening card from hugging the container’s left edge.
  • Horizontal snap rows — Add space before the first snapped item when swiping sideways.
  • Fixed side UI — Offset targets so they do not sit under a sticky left sidebar or toolbar.
  • Anchor jumps — Improve in-page navigation when a target should not touch the left viewport edge.

For RTL or international layouts, consider scroll-margin-inline-start instead of hard-coded left rules.

👀 Live Preview

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

1
2
3
4

Left scroll margin creates breathing room on the leading side when each item snaps into view.

Examples Gallery

Start with the reference page-scroll example, add left space on the first snap slide, improve a carousel opening panel, and apply left offset on one slide only.

📜 Left Offset

Add space at the left edge when an element is scrolled into view — matching the reference example.

Example 1 — scroll-margin-left on a page target

In this example, we’ll add a left margin of 50px when the element is scrolled into view.

index.html
<style>
  .scroll-margin-example {
    scroll-margin-left: 50px;
    margin-top: 100vh;
  }
</style>

<h1>CSS scroll-margin-left Example</h1>
<p>Scroll down to see the effect.</p>
<div class="scroll-margin-example">
  Scroll to this element
</div>
Try It Yourself

How It Works

The browser expands the scroll snap area on the left before settling the scroll position.

Example 2 — First snap slide spacing

Add scroll-margin-left to the first snapped slide so it does not hug the container’s leading edge.

first-slide.css
.slide:first-child {
  scroll-snap-align: start;
  scroll-margin-left: 24px;
}
Try It Yourself

How It Works

Only the opening slide needs left offset when later slides already have natural spacing on the right.

📄 Horizontal Layouts

Improve sideways scroll experiences such as carousels, tab strips, and overflow toolbars.

Example 4 — Left offset on one slide only

Use the property when only the left side needs adjustment: scroll-margin-left: 3rem;.

slide-left.css
#slide-left {
  scroll-margin-left: 3rem;
}
Try It Yourself

How It Works

You can set left scroll offset on one target without changing right-side behavior.

scroll-margin-left in the family

scroll-margin-left is the left longhand of scroll-margin. For the opposite side, see scroll-margin-right.

shorthand-equivalent.css
/* These are equivalent when only left matters */
.a { scroll-margin-left: 2rem; }
.b { scroll-margin: 0 0 0 2rem; }

🧠 How scroll-margin-left Works

1

Scroll target is selected

A link, script, or snap rule focuses on an element with scroll-margin-left.

Target
2

Left snap area grows

The browser adds the specified offset beyond the element’s left edge.

Offset
3

Scroll position settles

The element lands with the extra left-side space visible in the scrollport.

Position
=

Comfortable left stops

Targets no longer feel cramped against the left edge of the container or viewport.

Browser Compatibility

The scroll-margin-left 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.

Physical scroll margins · Modern support

Reliable left-side support

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

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 first-slide and anchor jumps on mobile browsers to confirm the left offset feels right.

scroll-margin-left property 97% supported

Bottom line: scroll-margin-left is safe to use in modern projects for scroll targets that need left-side offset.

Conclusion

The scroll-margin-left property is a useful tool for web developers looking to control the positioning of elements when they are scrolled into view.

By adding a left margin, you can ensure that important elements are not obscured by the edge of the viewport, improving the user experience. Experiment with different values to see how this property can enhance the layout and navigation of your web projects.

💡 Best Practices

✅ Do

  • Apply scroll-margin-left on the scroll target element
  • Use it on the first carousel slide or opening horizontal snap panel
  • Use scroll-margin-inline-start instead when you need RTL-safe logical layout
  • Test with scrollIntoView() and anchor links
  • Combine with horizontal scroll-snap-type for carousels

❌ Don’t

  • Set it on the scroll container expecting container padding
  • Confuse it with margin-left layout spacing
  • Assume left offset is always correct in RTL writing modes
  • Use huge percentages without testing on small screens
  • Forget scroll-margin-right when the right edge also needs space

Key Takeaways

Knowledge Unlocked

Five things to remember about scroll-margin-left

Use these points when offsetting left scroll targets.

5
Core concepts
02

left

Physical edge.

Axis
03

longhand

One side.

Detail
04

carousel

First slides.

Use case
🔄 05

scroll-margin

Four-side shorthand.

Companion

❓ Frequently Asked Questions

scroll-margin-left adds scroll offset at the left edge of an element when it is scrolled into view. It helps prevent targets from sitting flush against the left side of the viewport or scroll container.
No. It works with anchor links, focus navigation, scrollIntoView(), and scroll snapping in any scroll container. Horizontal layouts are a common use case because left offset is easy to see when scrolling sideways.
scroll-margin-left is a physical property that always targets the left edge. scroll-margin-left is logical and follows the inline direction, which may map to the right in RTL writing modes.
The default value is 0, meaning no extra left offset is applied.
Use it when a scroll target should stop before the left edge, such as the first carousel card, a horizontal snap item, or an element scrolled to inside an overflow panel.

Practice in the Live Editor

Open the HTML editor and try scroll-margin-left: 50px on a scroll target.

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