CSS scroll-margin-block Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The scroll-margin-block property is a shorthand for scroll-margin-block-start and scroll-margin-block-end. It adds outsets to a snap target’s scroll snap area on the block axis.

In a horizontal writing mode that usually means top and bottom. It is not inherited. Both longhands start at 0. Pair it with scroll-snap-type on the container and scroll-snap-align on the target.

Logical shorthand.

Standard-track and Baseline Widely available. Prefer it over physical top/bottom margins when the layout may switch writing mode. It accepts lengths only — not percentages.

CSS Syntax

syntax.css
scroll-margin-block: <length> | <length> <length> | initial | inherit;

One value sets both sides. Two values set start then end.

Property Values

ValueDescriptionTry it
0Default. No extra outset on either block edgeTry it
one <length>Same outset on block-start and block-end, e.g. 40pxTry it
two <length>sStart then end, e.g. 0 2remTry it
with snap endOutset is most visible when snapping to the block endTry it
initialResets both sides to 0Try it
inheritTakes the parent’s scroll-margin-blockTry it

How to Use scroll-margin-block

Set up vertical snap, then offset the target’s snap area on the block axis.

  1. Make a scroll container with overflow-y: auto (or scroll) and scroll-snap-type: y mandatory.
  2. Mark snap targets with scroll-snap-align.
  3. Set scroll-margin-block on the target that needs breathing room.
  4. Use one length for both sides, or two lengths for start and end.
PieceRequired?Role
Scroll containerYesoverflow-y + scroll-snap-type
scroll-snap-alignYesChooses which edge of the target snaps
scroll-margin-blockYesOutsets the snap area on the block axis
Length valuesYespx, rem, em — not %

Live Preview

Scroll the box vertically. Panel 2 is the snap target. Change scroll-margin-block and snap again.

Panels use scroll-snap-align: start. The margin on panel 2 leaves space before that start edge.

Scroll ↓
1
2
3

scroll-margin-block: 40px

CSS Examples

Each snippet focuses on scroll-margin-block. Use Try It Yourself for a live editor.

Example 1 — One Length Both Sides

Give the snap target the same block outset on start and end.

CSS
<style>
  .scroller {
    overflow-y: auto;
    scroll-snap-type: y mandatory;
  }

  .panel {
    scroll-snap-align: start;
  }

  .target {
    scroll-margin-block: 40px;
  }
</style>

<div class="scroller">
  <div class="panel">1</div>
  <div class="panel target">2</div>
  <div class="panel">3</div>
</div>
Try It Yourself

How It Works

  1. Enable vertical snap. scroll-snap-type: y mandatory makes the scroller stop on snap points.
  2. Align to start. scroll-snap-align: start snaps each panel’s block-start edge.
  3. Offset panel 2. scroll-margin-block: 40px grows that panel’s snap area by 40px on both sides.
  4. Scroll and compare. Panel 2 rests with 40px of breathing room instead of flush against the edge.

Example 2 — Start and End Values

Set different outsets for block-start and block-end.

CSS
<style>
  .scroller {
    overflow-y: auto;
    scroll-snap-type: y mandatory;
  }

  .panel {
    scroll-snap-align: start;
  }

  .target {
    scroll-margin-block: 0 2rem;
  }
</style>

<div class="scroller">
  <div class="panel">1</div>
  <div class="panel target">2</div>
  <div class="panel">3</div>
</div>
Try It Yourself

How It Works

  1. Same snap setup. The scroller and panels still snap on the block start.
  2. Two values. 0 2rem means start = 0, end = 2rem.
  3. End gets the room. Only the block-end side of the snap area grows.
  4. Shorthand maps cleanly. That is the same as setting the two longhands separately.

Example 3 — Snap to Block End

When you snap to the end edge, the end margin is the one you notice most.

CSS
<style>
  .scroller {
    overflow-y: auto;
    scroll-snap-type: y mandatory;
  }

  .panel {
    scroll-snap-align: end;
  }

  .target {
    scroll-margin-block: 1rem;
  }
</style>

<div class="scroller">
  <div class="panel">1</div>
  <div class="panel target">2</div>
  <div class="panel">3</div>
</div>
Try It Yourself

How It Works

  1. Snap to end. scroll-snap-align: end uses the block-end edge as the snap point.
  2. Add a 1rem outset. Both sides get 1rem, but the end edge is the one that lines up in the snapport.
  3. Stop short of flush. The scroller settles with about 1rem of space past that end edge.
  4. You could set only the end. scroll-margin-block-end: 1rem would be enough for this pattern.

Edge Cases & Pitfalls

If the offset never shows, scroll snap is usually incomplete.

snap

Needs a snap container and align

Without scroll-snap-type and scroll-snap-align, scroll-margin-block has nothing useful to offset.

%

Percentages are not valid

The formal syntax is lengths only. Use px, rem, or em — not %.

vs

Not the same as scroll-padding-block

scroll-padding-block insets the scroll container’s snapport. scroll-margin-block expands the target’s snap area.

axis

Block follows writing mode

In vertical writing modes the block axis is horizontal, so this property offsets left/right instead of top/bottom.

edge

Only the snapped edge feels obvious

If you snap to end, the end margin is what you notice. Setting only that longhand is often enough.

Browser Support

scroll-margin-block is a browser layout property for scroll snap. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available since 2021

scroll-margin-block

Chrome 69+, Firefox 68+, Safari 15+, Edge 79+, Opera 56+, Samsung Internet 10.1+. Internet Explorer does not support it.

97% Modern browsers
Google Chrome 69+
Full support
Mozilla Firefox 68+
Full support
Apple Safari 15+
Full support
Microsoft Edge 79+
Full support
Opera 56+
Full support
Samsung Internet 10.1+
Full support
Internet Explorer No support
Not supported
scroll-margin-block Widely supported

Bottom line: Safe for modern scroll-snap UIs. Skip Internet Explorer. Pair with scroll-snap-type and scroll-snap-align or the offset will not show.

Key Takeaways

  • Role: shorthand for block-start and block-end scroll margins on a snap target.
  • Values: one length for both sides, or two lengths for start then end.
  • Initial value: 0 on both longhands. Not inherited. No percentages.
  • Tip: use scroll-padding-block on the container when you want to inset the snapport instead.

One line: scroll-margin-block gives a snap target breathing room on the block axis — after scroll snap is already set up.

Frequently Asked Questions

It is a shorthand that sets scroll margins on the block axis — scroll-margin-block-start and scroll-margin-block-end. Those outsets enlarge the scroll snap area so snapping stops a little before or after the element's edge.
Both longhands default to 0. There is no extra outset until you set one.
It mainly affects scroll snapping. You still need a scroll container with scroll-snap-type and snap targets with scroll-snap-align for the offset to show during snap scrolling.
scroll-margin-block is set on the snap target (the child). scroll-padding-block is set on the scroll container and insets the snapport itself.
No. Set it on the element that snaps. Percentages are not valid; use lengths such as px, rem, or em.
It is Baseline and widely available since September 2021: Chrome 69+, Firefox 68+, Safari 15+, Edge 79+, Opera 56+. Internet Explorer does not support it. It is a browser layout property, not a Node.js feature.

Next: scroll-margin-block-end

Learn the longhand that sets only the block-end scroll margin.

scroll-margin-block-end tutorial →

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