CSS Portal

CSS scroll-margin-right 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-right property controls an extra offset on the right edge of an element’s snap area that the browser uses when bringing that element into view via scrolling (for example, during scroll snapping or when programmatically scrolling an element into view). In other words, it shifts the effective “landing zone” on the right side so the element doesn’t end up flush against the scroll container’s right edge. This adjustment is applied only to the snapping/scrolling behavior; it does not change the element’s layout, box model, or how it participates in document flow.

In practice this property is useful when you want items to stop slightly away from the right edge of a scroll container — for instance, in a horizontally scrolling carousel, a list of cards, or when compensating for a fixed overlay at the right side of the viewport. It’s commonly combined with smooth scrolling and programmatic calls like element.scrollIntoView to produce a visually pleasing final position where the focused element has breathing room instead of being jammed against the container boundary. Because it only affects the snap/scroll target, it won’t affect hit testing or the spatial relationships used by other layout rules.

Conceptually scroll-margin-right is one side-specific member of the scroll-margin family; you can control all sides together with the shorthand scroll-margin, or prefer the writing-mode–aware logical counterpart scroll-margin-inline-end for internationalized layouts. It interacts with the container-side configuration — for example, scroll-padding-right adjusts the container’s snapport and therefore complements element-side margins — and with alignment rules such as scroll-snap-align, which determines which point of the element is aligned when snapping occurs. A common pitfall is expecting this property to change the element’s normal visual spacing; instead, treat it as an offset that only affects where the element ends up after scrolling or snapping.

Definition

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

Interactive Demo

1
2
3
Scroll »

Syntax

scroll-margin-right: <length>

Values

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

Example

<div class='wrap'>
<h2>Horizontal scroll with scroll-margin-right</h2>
<p>Scroll the row - the green card has scroll-margin-right to add extra space when snapped.</p>

<div class='carousel' tabindex='0'>
<div class='card'>1</div>
<div class='card'>2</div>
<div class='card special' id='special'>3 (has scroll-margin-right)</div>
<div class='card'>4</div>
<div class='card'>5</div>
</div>
</div>
/* Container and general styles */
.wrap {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
    padding: 20px;
    max-width: 900px;
    margin: 0 auto;
}

.carousel {
    margin-top: 12px;
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 12px;

    /* Enable scroll snapping on the inline (x) axis */
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.card {
    flex: 0 0 280px;
    height: 160px;
    background: #f0f0f0;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #222;

    /* Snap each card to the start of the scroll container */
    scroll-snap-align: start;
}

.card.special {
    background: #8fd19e;

    /* Add extra space to the right when this element is brought into view */
    scroll-margin-right: 80px;
}

/* Optional: make focus outline visible when scrolling via keyboard */
.carousel:focus {
    outline: 2px dashed rgba(0,0,0,0.12);
    outline-offset: 6px;
}

Browser Support

The following information will show you the current browser support for the CSS scroll-margin-right 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!