CSS scroll-margin-block Property

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

What You’ll Learn

The scroll-margin-block property sets scroll offsets on the block axis. It is the logical companion to physical top/bottom scroll margins and works well with scroll snapping and anchor navigation.

01

block

Vertical flow axis.

02

start

Block-start side.

03

end

Block-end side.

04

snap

Scroll snapping.

05

length

px, rem, %.

06

logical

Writing-mode safe.

Introduction

The scroll-margin-block property in CSS is used to adjust the scroll snap area at the block start and block end of an element.

This property is particularly useful when implementing scroll snapping in a vertical writing mode or when you need to add margins to the scroll snap position. By using this property, you can control the proximity of elements to the container’s scroll position, enhancing the scrolling experience.

Definition and Usage

scroll-margin-block is a logical shorthand for scroll-margin-block-start and scroll-margin-block-end. Apply it to the element that becomes a scroll target.

In standard horizontal writing mode, block-start maps to the top and block-end maps to the bottom. That makes scroll-margin-block: 4rem 1rem similar to setting top and bottom scroll offsets, but it stays correct if the writing mode changes.

💡
Beginner Tip

On a normal English webpage, think of scroll-margin-block as “top and bottom scroll offset” that follows the document’s block direction.

📝 Syntax

The syntax for the scroll-margin-block property is straightforward and allows you to specify the margin for the block start and block end.

syntax.css
element {
  scroll-margin-block: block-start block-end;
}

Here, block-start and block-end can be any valid CSS length value (e.g., px, em, rem) or a percentage.

Basic Example

scroll-margin-block.css
section {
  scroll-margin-block: 20px;
}

Longhand Properties

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

Syntax Rules

  • One value sets both block-start and block-end equally.
  • Two values set block-start first, then block-end.
  • Percentages are relative to the element’s block size.
  • Works with anchor links, scrollIntoView(), and scroll snapping.

🎯 Default Value

The default value of the scroll-margin-block property is 0, meaning no additional margin is added to the scroll snap area.

⚡ Quick Reference

QuestionAnswer
Default value0
Horizontal writing modeUsually top and bottom scroll offset
Shorthand forscroll-margin-block-start + scroll-margin-block-end
Accepted valuesLengths and percentages
InheritedNo
AnimatableNo

💎 Property Values

ValueExampleDescription
lengthscroll-margin-block: 20px;Specifies a fixed margin (e.g., 10px, 2em, 1rem).
percentagescroll-margin-block: 10%;Specifies a margin relative to the block size of the element (e.g., 10%).
20px 4rem 1rem 10%

When to Use scroll-margin-block

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

  • Scroll snapping — Keep snapped sections away from container edges.
  • Sticky headers — Offset block-start so titles stay visible below fixed UI.
  • International layouts — Prefer logical properties over hard-coded top/bottom rules.
  • Documentation pages — Fine-tune where chapter anchors land vertically.

For left/right offsets, use scroll-margin-inline instead.

👀 Live Preview

Scroll inside the panel. Each section uses scroll-snap-align: start and scroll-margin-block: 12px.

Section 1
Section 2
Section 3

The block-axis margin creates breathing room when each panel snaps into view.

Examples Gallery

Start with the reference scroll-snap example, set different block-start and block-end values, try a scroll container, and use scroll-margin-block-start with a sticky header.

📜 Block-Axis Offsets

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

Example 1 — scroll-margin-block with scroll snap

In this example, we’ll add scroll margin to a section element to ensure it doesn’t touch the edges when snapped into view.

index.html
<style>
  html {
    scroll-snap-type: y mandatory;
  }

  section {
    height: 100vh;
    scroll-snap-align: start;
    scroll-margin-block: 20px;
  }
</style>

<section>Section 1</section>
<section>Section 2</section>
<section>Section 3</section>
Try It Yourself

How It Works

scroll-margin-block expands the scroll target area on the block axis before the browser settles the snap position.

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

Use two values when the top and bottom scroll offsets should differ: scroll-margin-block: 4rem 1.5rem;.

start-end.css
section[id] {
  scroll-margin-block: 4rem 1.5rem;
}
Try It Yourself

How It Works

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

🗃 Scroll Containers

Use block-axis margins inside overflow panels and documentation layouts.

Example 3 — Block margin inside a scroll box

Combine scroll-snap-type on the container with scroll-margin-block on each panel.

container-snap.css
.panel {
  scroll-snap-align: start;
  scroll-margin-block: 16px;
}
Try It Yourself

How It Works

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

Example 4 — scroll-margin-block-start

When only the block-start side needs offset, use the longhand: scroll-margin-block-start: 3.5rem;.

block-start.css
article {
  scroll-margin-block-start: 3.5rem;
}
Try It Yourself

How It Works

Longhands let you offset only one logical side when the other side does not need adjustment.

scroll-margin-block vs scroll-margin

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

Pair with scroll-behavior: smooth for animated anchor navigation and with scroll-snap-align for snapped carousels or section scrollers.

logical-vs-physical.css
/* Physical shorthand */
.physical { scroll-margin-top: 4rem; }

/* Logical equivalent in horizontal writing */
.logical { scroll-margin-block-start: 4rem; }

🧠 How scroll-margin-block Works

1

Block axis is determined

Writing mode decides which sides are block-start and block-end.

Logical
2

Scroll target area grows

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

Offset
3

Browser scrolls into place

Anchor links, focus, scrollIntoView(), or snap positioning use the expanded area.

Position
=

Comfortable block-axis stops

Snapped and linked content lands with space on the block axis.

Browser Compatibility

The scroll-margin-block 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-block 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 scroll snapping and anchor jumps on iOS Safari — block-axis offsets should match your real sticky header height.

scroll-margin-block property 97% supported

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

Conclusion

The scroll-margin-block property is a useful tool for web developers looking to fine-tune the scrolling experience on their websites.

By adding margins to the scroll snap area, you can ensure a more comfortable and visually appealing layout. Experiment with different values to see how this property can improve the usability of your scrollable content.

💡 Best Practices

✅ Do

  • Prefer logical scroll-margin-block for international layouts
  • Pair with scroll-snap-align on snapped children
  • Match block-start offset to sticky header height
  • Use rem for scalable documentation offsets
  • Test anchor links and snap scrolling on mobile

❌ Don’t

  • Confuse scroll-margin-block with regular margin-block
  • Apply it to the scroll container instead of the target
  • Assume block-start always means top in every writing mode
  • Forget horizontal offsets when content needs side inset
  • Use huge percentage values without testing small screens

Key Takeaways

Knowledge Unlocked

Five things to remember about scroll-margin-block

Use these points when offsetting block-axis scroll targets.

5
Core concepts
02

block axis

Logical flow.

Axis
03

start / end

Two sides.

Values
04

snap

Scroll snapping.

Use case
🔄 05

longhands

block-start.

Detail

❓ Frequently Asked Questions

scroll-margin-block sets the scroll offset on the block axis — block-start and block-end — when an element is scrolled into view. In normal horizontal writing mode, that usually means top and bottom.
scroll-margin is the physical shorthand for all four sides. scroll-margin-block is a logical shorthand that targets only the block axis, which adapts correctly in vertical writing modes.
They are logical directions. In horizontal left-to-right writing, block-start is the top and block-end is the bottom. In vertical writing modes, they map to the corresponding block flow sides.
The default value is 0, meaning no extra block-axis offset is applied to the scroll target.
Use it when you want block-axis scroll offsets that work with logical layout, especially with scroll snapping, anchor links, or scrollIntoView on vertically flowing content.

Practice in the Live Editor

Open the HTML editor and try scroll-margin-block: 20px with scroll-snap-align.

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