Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

CSS scroll-margin-inline-end Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The scroll-margin-inline-end property defines an extra offset on the inline-end side of an element that the browser uses when bringing that element into view via scrolling or when snapping to it. It does not change the element’s position in normal layout or its computed box model; instead, it influences the scroll target alignment by adding space between the element’s border edge and the scroller’s inner edge on the element’s inline-end side. This makes it useful for adjusting how “close” a target appears to the scroller’s edge after a programmatic scroll or a snap operation without altering surrounding flow.

Because scroll-margin-inline-end is a logical property, its effect follows writing mode and directionality: what counts as the inline end varies with the element’s writing-mode and direction. In a horizontal LTR context the inline end corresponds to the physical right side; in RTL it becomes the physical left. In vertical writing modes the inline axis is orthogonal to the block axis, so the “inline end” maps to a different physical side accordingly. This logical behavior makes scroll-margin-inline-end a convenient way to author cross-directional spacing for scroll targets without writing separate rules for each language or layout orientation.

You’ll commonly use scroll-margin-inline-end alongside the broader scroll-margin shorthands and related scroll properties. For example, the values set by scroll-margin or scroll-margin-inline can affect both inline sides and block sides together, while margin-inline-end is the ordinary layout margin that moves boxes in the flow (so it’s not interchangeable with scroll margins). For scroll-snapping scenarios you often combine a scroll margin with scroll-snap-align to control which element is treated as the snap target and where it finishes relative to the container, and you may consider the scroller’s interior spacing via scroll-padding-inline to balance offsets between container padding and target scroll margins.

Practical use cases include ensuring anchored content isn’t obscured by fixed-position UI (headers, toolbars) after a jump-to-anchor, creating consistent spacing when snapping horizontally between items, or fine-tuning the visual alignment of elements brought into view programmatically. Remember that this property only affects how the scrolling algorithm calculates the final snapped/visible position of the element; it doesn’t create visual gaps in normal layout or change hit-testing for surrounding content.

Definition

Initial value
0
Applies to
all elements
Inherited
no
Computed value
as specified
Animatable
by computed value type
JavaScript syntax
object.style.scrolllMarginInlineEnd

Interactive Demo

1
2
3
Scroll »

Syntax

scroll-margin-inline-end: >length<

Values

  • >length<An outset from the corresponding edge of the scroll container.

Example

  <body>
<nav class="nav">
<a href="#card-3">Jump to card 3 (no margin)</a>
<a href="#card-4">Jump to card 4 (with scroll-margin-inline-end)</a>
</nav>

<div class="carousel" tabindex="0">
<article id="card-1" class="card">Card 1</article>
<article id="card-2" class="card">Card 2</article>
<article id="card-3" class="card">Card 3</article>
<article id="card-4" class="card with-margin">Card 4 (has scroll-margin-inline-end)</article>
<article id="card-5" class="card">Card 5</article>
<article id="card-6" class="card">Card 6</article>
</div>
</body>
  * {
    box-sizing: border-box;
  }

  body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
    margin: 24px;
    color: #111827;
    background: #f8fafc;
  }

  .nav {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
  }

  .nav a {
    text-decoration: none;
    padding: 8px 12px;
    background: #1f2937;
    color: white;
    border-radius: 6px;
    font-size: 14px;
  }

  .carousel {
    display: flex;
    gap: 16px;
    padding: 16px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    background: linear-gradient(90deg, #fff 0%, #f1f5f9 100%);
    border: 1px solid #e2e8f0;
    border-radius: 10px;
  }

  .card {
    flex: 0 0 220px;
    height: 140px;
    background: linear-gradient(180deg, #60a5fa 0%, #3b82f6 100%);
    color: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 18px;
    scroll-snap-align: start;
  }

  /* The example: add extra inline-end margin so when this element is scrolled into view
     the container leaves additional space at its inline end (right side in LTR). */
  .with-margin {
    scroll-margin-inline-end: 120px;
  }

  /* Small accessibility hint when keyboard focusing the scroll container */
  .carousel:focus {
    outline: 3px solid rgba(59,130,246,0.25);
    outline-offset: 4px;
  }

Browser Support

The following information will show you the current browser support for the CSS scroll-margin-inline-end property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!