CSS scroll-margin-block-start Property

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

What You’ll Learn

The scroll-margin-block-start property offsets a scroll target at the block-start edge. It is one of the most practical scroll-margin longhands for fixing sticky-header overlap on anchor links.

01

block-start

Logical top.

02

offset

Scroll stop space.

03

sticky

Header fix.

04

anchors

#section links.

05

JS scroll

scrollIntoView.

06

writing mode

Logical layout.

Introduction

The scroll-margin-block-start property in CSS is used to set the margin at the start of the block axis for an element when it is scrolled into view.

This property is particularly useful for controlling the position of an element when it is brought into view via scrolling, such as with scrollIntoView(). The block axis depends on the element’s writing mode, which means it will be vertical in horizontal writing modes and horizontal in vertical writing modes.

Definition and Usage

Apply scroll-margin-block-start to the element being scrolled to — section headings, chapter articles, snap panels, or any anchor target.

It is the block-start longhand of scroll-margin-block. On a typical English webpage, it often behaves like scroll-margin-top, but stays correct in logical layouts.

💡
Beginner Tip

If a sticky nav covers section titles after clicking in-page links, set scroll-margin-block-start to the header height.

📝 Syntax

The syntax for the scroll-margin-block-start property is simple and allows you to set a margin using any CSS length value.

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

Here, value can be a length (e.g., 10px, 2em, 5%, etc.).

Basic Example

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

Related Properties

  • scroll-margin-block-end — offset at the block-end edge
  • scroll-margin-block — shorthand for start and end
  • scroll-margin-top — physical top offset

🎯 Default Value

The default value of the scroll-margin-block-start property is 0. This means that by default, no additional margin is added at the start of the block axis when the element is scrolled into view.

⚡ Quick Reference

QuestionAnswer
Default value0
Horizontal writing modeUsually top scroll offset
Part ofscroll-margin-block shorthand
Accepted valuesLengths and percentages
InheritedNo
AnimatableNo

💎 Property Values

ValueExampleDescription
lengthscroll-margin-block-start: 50px;Specifies a fixed value for the scroll margin. This can be any valid CSS length unit such as px, em, rem, vh, etc.
percentagescroll-margin-block-start: 10%;Specifies a percentage relative to the element’s block size.
50px 4rem 10%

When to Use scroll-margin-block-start

scroll-margin-block-start solves the most common scroll-position problem on documentation sites:

  • Sticky navigation — Keep section headings visible below a fixed or sticky header.
  • Anchor links — Improve table-of-contents jumps on long pages.
  • scrollIntoView() — Offset programmatic scroll targets.
  • Scroll snapping — Add top breathing room on the first snapped panel.

For the block-end side (usually bottom), use scroll-margin-block-end instead.

👀 Live Preview

Scroll inside the box. The blue target uses scroll-margin-block-start: 2.5rem below the sticky label.

Sticky nav simulation
Scroll target with block-start offset

The target stops with extra space at its block-start edge instead of touching the top.

Examples Gallery

Start with the reference container example, fix sticky-header overlap, add block-start space on the first snap panel, and use rem units with a fixed banner.

📜 Block-Start Offset

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

Example 1 — scroll-margin-block-start: 50px

In this example, we’ll set the scroll margin at the start of the block axis to 50px for a paragraph element.

index.html
<style>
  .container {
    height: 200px;
    overflow-y: scroll;
  }

  .target {
    scroll-margin-block-start: 50px;
    background-color: lightblue;
  }
</style>

<div class="container">
  <p class="target">Scroll to me!</p>
</div>
<button onclick="document.querySelector('.target').scrollIntoView();">
  Scroll to Target
</button>
Try It Yourself

How It Works

The browser expands the scroll snap area at block-start before settling the scroll position.

Example 2 — Sticky header offset

Match scroll-margin-block-start to your sticky navigation height so linked headings stay readable.

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

How It Works

Measure the sticky header height and use the same value (or slightly more) for block-start offset.

🗃 Snap Panels & Units

Fine-tune the first snapped item and use scalable rem offsets on docs pages.

Example 3 — First snap panel spacing

Add scroll-margin-block-start to the first snapped panel so it does not hug the container top.

first-panel.css
.panel:first-child {
  scroll-snap-align: start;
  scroll-margin-block-start: 20px;
}
Try It Yourself

How It Works

Only the first panel needs block-start offset when later panels already have natural spacing above them.

Example 4 — rem units with a fixed banner

Use scroll-margin-block-start: 3.5rem so chapters clear a fixed top banner.

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

How It Works

rem keeps the offset proportional when users change default text size settings.

scroll-margin-block-start in the family

scroll-margin-block-start is the block-start longhand of scroll-margin-block. For the opposite side, see scroll-margin-block-end.

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

🧠 How scroll-margin-block-start Works

1

Writing mode sets block-start

The browser maps block-start based on the element’s writing mode and direction.

Logical
2

Scroll target area grows

scroll-margin-block-start adds offset beyond the block-start edge.

Offset
3

Scroll position settles

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

Position
=

Readable block-start stops

Headings and targets stay visible, even with sticky UI chrome.

Browser Compatibility

The scroll-margin-block-start 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 block-start support

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

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 anchor navigation on mobile Safari and Chrome with your real sticky header height.

scroll-margin-block-start property 97% supported

Bottom line: scroll-margin-block-start is widely supported and ideal for sticky-header anchor fixes in modern projects.

Conclusion

The scroll-margin-block-start property is a useful tool for web developers aiming to control the scroll position of elements more precisely.

By setting the margin at the start of the block axis, you can ensure that elements are displayed in a visually appealing and accessible manner when scrolled into view. Experiment with different values to see how this property can improve the user experience on your web projects.

💡 Best Practices

✅ Do

  • Apply scroll-margin-block-start on scroll target elements
  • Match the offset to sticky or fixed header height
  • Prefer logical block-start over hard-coded top when possible
  • Use rem for scalable documentation layouts
  • Pair with scroll-behavior: smooth for in-page nav

❌ Don’t

  • Set it on the scroll container expecting padding
  • Confuse it with margin-block-start layout spacing
  • Assume block-start always equals top in every writing mode
  • Forget block-end offset when footers need bottom space
  • Use huge percentage values without testing small screens

Key Takeaways

Knowledge Unlocked

Five things to remember about scroll-margin-block-start

Use these points when fixing block-start scroll targets.

5
Core concepts
02

block-start

Logical edge.

Axis
03

sticky

Header fix.

Pattern
04

longhand

One side.

Detail
🔄 05

block

Shorthand pair.

Companion

❓ Frequently Asked Questions

scroll-margin-block-start adds scroll offset at the block-start edge of an element when it is scrolled into view. In horizontal writing mode, block-start is usually the top.
top is a physical direction. block-start is logical and follows the document block flow, so it stays correct in vertical writing modes.
scroll-margin-block is a shorthand for both block-start and block-end. scroll-margin-block-start sets only the block-start side.
The default value is 0, meaning no extra block-start offset is applied.
Use it when a scroll target would sit under a sticky header or too close to the top of the viewport, such as for anchor links, scrollIntoView targets, and snapped panels.

Practice in the Live Editor

Open the HTML editor and try scroll-margin-block-start: 4rem with sticky navigation.

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