CSS scroll-margin-block-start Property

The CSS scroll-margin-block-start property sets the scroll margin at the logical block-start edge of an element.

It adjusts the area used to align an element when scrolling, without changing the element's layout dimensions or spacing. The block-start edge follows the element's writing mode, making this property useful for anchor navigation, sticky headers, scroll snapping, and layouts with different text directions.

scroll-margin-block-start Syntax

The scroll-margin-block-start property accepts one CSS length value or a CSS-wide keyword.

Basic Syntax

selector {
  scroll-margin-block-start: 20px;
}

Available Values

.target {
  scroll-margin-block-start: 0;
}
.target {
  scroll-margin-block-start: 20px;
}
.target {
  scroll-margin-block-start: 2rem;
}
.target {
  scroll-margin-block-start: 1.5em;
}
.target {
  scroll-margin-block-start: -10px;
}
.target {
  scroll-margin-block-start: calc(3rem + 10px);
}

CSS-Wide Keywords

.target {
  scroll-margin-block-start: initial;
}
.target {
  scroll-margin-block-start: inherit;
}
.target {
  scroll-margin-block-start: unset;
}
.target {
  scroll-margin-block-start: revert;
}
.target {
  scroll-margin-block-start: revert-layer;
}

Positive values expand the scroll alignment area at block-start. Negative values contract it. Percentages and auto are not accepted.

Property Values

Value Description
<length> Sets the scroll margin at the logical block-start edge using a CSS length.
0 Applies no additional block-start scroll margin. This is the initial value.
Positive length Expands the scroll alignment area beyond the block-start edge.
Negative length Contracts the scroll alignment area at block-start.
calc() Calculates a length using a valid CSS mathematical expression.
initial Resets the property to 0.
inherit Uses the computed value from the parent element.
unset Resets the property to 0 because it is not inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value 0
Inherited No
Applies to All elements
Computed value Absolute length
Animation type By computed value, as a length
Percentages Not accepted

Valid Values

.target {
  scroll-margin-block-start: 40px;
}
.target {
  scroll-margin-block-start: 3rem;
}
.target {
  scroll-margin-block-start: 0;
}
.target {
  scroll-margin-block-start: -5px;
}
.target {
  scroll-margin-block-start: calc(2rem + 15px);
}

Invalid Values

.target {
  scroll-margin-block-start: auto;
}
.target {
  scroll-margin-block-start: 10%;
}
.target {
  scroll-margin-block-start: 10px 20px;
}
.target {
  scroll-margin-block-start: smooth;
}
.target {
  scroll-margin-block-start: 2s;
}

This longhand property accepts only one length value. Percentages, multiple lengths, and scrolling behavior keywords are invalid.

How It Works

The scroll-margin-block-start property adjusts the scroll alignment area surrounding an element at its logical block-start edge.

When the browser scrolls the element into view, this additional area can affect where the target is positioned within the scroll container.

Default Scroll Margin

.target {
  scroll-margin-block-start: 0;
}

No additional block-start scroll margin is applied.

Adding a Positive Scroll Margin

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

The scroll alignment area extends 60 pixels beyond the target's block-start edge.

Using a Negative Scroll Margin

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

The alignment area contracts by 10 pixels at block-start.

Using Relative Units

.target {
  scroll-margin-block-start: 4rem;
}

Relative units are useful when scroll offsets should scale with typography or design settings.

No Effect on Document Flow

The property does not change the element's dimensions or create additional space between neighboring elements.

Scroll Range Limitations

The final position depends on the available scroll range. A target near the beginning or end of a container may not reach its preferred alignment position.

Writing Modes and Logical Directions

The block-start edge is determined by the element's writing mode rather than a fixed physical direction.

Horizontal Writing Mode

.target {
  writing-mode: horizontal-tb;
  scroll-margin-block-start: 40px;
}

In horizontal-tb, block-start corresponds to the top edge.

Vertical Right-to-Left Writing Mode

.target {
  writing-mode: vertical-rl;
  scroll-margin-block-start: 40px;
}

In vertical-rl, block-start corresponds to the right edge.

Vertical Left-to-Right Writing Mode

.target {
  writing-mode: vertical-lr;
  scroll-margin-block-start: 40px;
}

In vertical-lr, block-start corresponds to the left edge.

Writing Mode Reference

Writing Mode Block-Start Edge
horizontal-tb Top
vertical-rl Right
vertical-lr Left

Writing Mode Versus Text Direction

The direction property affects inline progression but does not independently reverse the block-start edge in horizontal writing.

Why Logical Properties Matter

Logical scroll margins allow the same CSS declaration to work across horizontal and vertical writing modes without manually changing physical edge properties.

Anchor Navigation and Sticky Headers

One common use for scroll-margin-block-start is providing space above anchor targets so sticky headers do not cover the beginning of a section.

HTML Example

<nav aria-label="Page sections">
  <a href="#introduction">Introduction</a>
  <a href="#examples">Examples</a>
  <a href="#summary">Summary</a>
</nav>
<section id="introduction">
  <h2>Introduction</h2>
  <p>Introduction content.</p>
</section>
<section id="examples">
  <h2>Examples</h2>
  <p>Example content.</p>
</section>
<section id="summary">
  <h2>Summary</h2>
  <p>Summary content.</p>
</section>

CSS Example

section[id] {
  scroll-margin-block-start: 90px;
}

In horizontal writing, each section receives a 90-pixel scroll margin above its top edge.

Sticky Header Example

.site-header {
  position: sticky;
  top: 0;
  height: 70px;
  z-index: 10;
}
section[id] {
  scroll-margin-block-start: 90px;
}

The additional offset can help keep section headings visible below the sticky header.

Combining With Smooth Scrolling

html {
  scroll-behavior: smooth;
}
section[id] {
  scroll-margin-block-start: 90px;
}
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

The scroll margin adjusts target alignment while scroll-behavior requests smooth scrolling.

Responsive Header Offsets

section[id] {
  scroll-margin-block-start: 100px;
}
@media (max-width: 600px) {
  section[id] {
    scroll-margin-block-start: 70px;
  }
}

Different offsets can accommodate changes in header size across viewport widths.

Important Consideration

Anchor navigation generally remains functional without this property. The scroll margin improves positioning rather than creating navigation behavior.

Scroll Snapping

The scroll-margin-block-start property can expand the snap area of an element at its logical block-start edge.

Vertical Scroll Snap Example

.scroll-panel {
  height: 300px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
}
.scroll-panel .item {
  scroll-snap-align: start;
  scroll-margin-block-start: 30px;
}

In horizontal writing, the snap area extends 30 pixels above each item.

Different Margins for Individual Items

.scroll-panel .item {
  scroll-margin-block-start: 20px;
}
.scroll-panel .item.featured {
  scroll-margin-block-start: 60px;
}

The featured item receives a larger block-start scroll margin.

Combining With Scroll Padding

.scroll-panel {
  scroll-padding-block-start: 20px;
}
.scroll-panel .item {
  scroll-margin-block-start: 30px;
}

Scroll padding adjusts the container's optimal viewing region, while scroll margin adjusts the alignment area around each target.

Important Consideration

Scroll margin does not activate scroll snapping. The container must define scroll-snap-type, and the targets must define appropriate snap alignment.

Using the scroll-margin-block Shorthand

The scroll-margin-block shorthand sets both block-start and block-end scroll margins.

Shorthand Declaration

.target {
  scroll-margin-block: 60px 20px;
}

The first value sets block-start to 60 pixels, and the second sets block-end to 20 pixels.

Equivalent Longhand Declarations

.target {
  scroll-margin-block-start: 60px;
  scroll-margin-block-end: 20px;
}

One Shorthand Value

.target {
  scroll-margin-block: 30px;
}

Both block edges receive 30 pixels of scroll margin.

Overriding Block-Start

.target {
  scroll-margin-block: 20px;
  scroll-margin-block-start: 80px;
}

The block-start margin becomes 80 pixels while block-end remains 20 pixels.

Declaration Order

.target {
  scroll-margin-block-start: 80px;
  scroll-margin-block: 20px;
}

The later shorthand resets both block-axis scroll margins to 20 pixels.

Important Consideration

Use the longhand property when only the block-start edge needs adjustment. Use the shorthand when both block edges require related values.

Logical Versus Physical Scroll Margins

Physical scroll margin properties refer to fixed edges, while logical properties follow the writing mode.

Property Edge
scroll-margin-block-start Logical block-start edge
scroll-margin-top Physical top edge
scroll-margin-right Physical right edge
scroll-margin-left Physical left edge

Physical Top Scroll Margin

.target {
  scroll-margin-top: 40px;
}

The scroll margin applies to the physical top edge regardless of writing mode.

Logical Block-Start Scroll Margin

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

The scroll margin follows the logical block-start edge.

Equivalent in Horizontal Writing

.target {
  writing-mode: horizontal-tb;
  scroll-margin-block-start: 40px;
}

In horizontal writing, this corresponds to scroll-margin-top: 40px.

Important Consideration

Physical and logical declarations can affect the same underlying edge. Normal CSS cascade rules determine which declaration applies when they overlap.

scroll-margin-block-start Versus scroll-padding-block-start

Both properties adjust block-start scrolling alignment, but they apply to different elements.

Property Applied To Purpose
scroll-margin-block-start Scroll target Expands or contracts the target's alignment area at block-start.
scroll-padding-block-start Scroll container Defines an inset at the container's block-start edge.

Target-Side Offset

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

Container-Side Offset

.scroll-container {
  scroll-padding-block-start: 60px;
}

Combining Both Properties

.scroll-container {
  scroll-padding-block-start: 20px;
}
.scroll-container .target {
  scroll-margin-block-start: 40px;
}

Both offsets can contribute to the final alignment of a target at block-start.

When to Use Each Property

Use scroll-padding-block-start for a consistent container-side offset. Use scroll-margin-block-start when individual targets need their own alignment spacing.

scroll-margin-block-start Example

The following example compares two scrollable panels. The first uses the default scroll margin, while the second adds 40 pixels at block-start.

HTML Example

<div class="scroll-start-demo">
  <div class="scroll-example">
    <h3>Without Scroll Margin</h3>
    <div class="scroll-panel">
      <div class="spacer">Scroll content</div>
      <div class="target">Target Element</div>
      <div class="spacer">More content</div>
    </div>
    <button type="button">Scroll to Target</button>
  </div>
  <div class="scroll-example with-margin">
    <h3>With Block-Start Scroll Margin</h3>
    <div class="scroll-panel">
      <div class="spacer">Scroll content</div>
      <div class="target">Target Element</div>
      <div class="spacer">More content</div>
    </div>
    <button type="button">Scroll to Target</button>
  </div>
</div>

CSS Example

.scroll-start-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}
.scroll-start-demo .scroll-panel {
  height: 180px;
  overflow-y: auto;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
}
.scroll-start-demo .spacer {
  height: 200px;
  padding: 15px;
  box-sizing: border-box;
}
.scroll-start-demo .target {
  padding: 15px;
  background-color: #bfdbfe;
  border: 2px solid #2563eb;
}
.scroll-start-demo .with-margin .target {
  scroll-margin-block-start: 40px;
}
.scroll-start-demo button {
  margin-top: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

JavaScript Example

document.querySelectorAll(".scroll-start-demo .scroll-example").forEach((example) => {
  const button = example.querySelector("button");
  const target = example.querySelector(".target");
  button.addEventListener("click", () => {
    target.scrollIntoView({
      behavior: window.matchMedia("(prefers-reduced-motion: reduce)").matches ? "instant" : "smooth",
      block: "start"
    });
  });
});
Browser Result

Without Scroll Margin

Scroll content
Target Element
More content

With Block-Start Scroll Margin

Scroll content
Target Element
More content

Click the button beneath each panel. The first target aligns near the top of its scroll container. The second target leaves approximately 40 pixels above the element because of its block-start scroll margin.

Increasing the Offset

.scroll-start-demo .with-margin .target {
  scroll-margin-block-start: 70px;
}

The target requests a larger block-start alignment offset.

Removing the Offset

.scroll-start-demo .with-margin .target {
  scroll-margin-block-start: 0;
}

The additional block-start scroll alignment space is removed.

Browser Compatibility Note

The final scroll position can vary according to browser behavior and available scroll range. Targets near the edges of a container may not reach the requested alignment position.

Accessibility Considerations

Block-start scroll margins can improve navigation by helping users see headings and other targets after scrolling.

Keep Headings Visible

Provide sufficient scroll margin to prevent sticky headers from covering the beginning of a section.

Support Keyboard Navigation

Ensure links and buttons that trigger scrolling remain keyboard accessible and have visible focus indicators.

Preserve Semantic Navigation

Use meaningful section headings, valid IDs, and standard anchor links whenever possible.

Consider Focus Management

Scrolling a target into view does not necessarily move keyboard focus to it. Scripted interfaces may require additional focus handling.

Respect Reduced Motion Preferences

Scroll margin does not animate scrolling, but smooth scrolling should account for users who prefer reduced motion.

Support Different Writing Modes

Logical properties help scrolling offsets follow the content's block direction.

Test Responsive Layouts

Verify that offsets remain appropriate when sticky header dimensions change at smaller viewport sizes or higher zoom levels.

Important Consideration

Scroll margins improve visual alignment but do not replace semantic HTML, accessible navigation controls, or focus management.

Common Mistakes

Using Percentages

.target {
  scroll-margin-block-start: 10%;
}

Percentages are invalid. Use a CSS length value.

Using auto

.target {
  scroll-margin-block-start: auto;
}

The property does not accept auto.

Providing Multiple Lengths

.target {
  scroll-margin-block-start: 10px 20px;
}

This longhand property accepts only one length value.

Confusing Block-Start With Top

Block-start corresponds to the top edge in horizontal writing, but it corresponds to the right or left edge in vertical writing.

Expecting Layout Spacing

Scroll margin does not create physical space between neighboring elements.

Applying the Property to the Wrong Element

Apply scroll-margin-block-start to the target. Use scroll-padding-block-start on the scroll container for container-side spacing.

Expecting Scroll Snapping Automatically

The property adjusts scroll alignment areas but does not enable scroll snapping by itself.

Ignoring Declaration Order

A later scroll-margin-block shorthand can override an earlier block-start longhand declaration.

Using Excessively Large Offsets

Large scroll margins may position targets farther from the scrollport edge than intended or exceed the available scroll range.

Confusing Scroll Margin With Smooth Scrolling

Scroll margin affects target alignment. The scroll-behavior property controls smooth scrolling.

Important Considerations

Keep the following points in mind when using scroll-margin-block-start:

  • It is a logical scroll margin longhand property.
  • Its initial value is 0, and it is not inherited.
  • It accepts one CSS length, including negative lengths and calculated lengths.
  • Percentages and auto are invalid.
  • The block-start edge depends on the element's writing mode.
  • In horizontal-tb, block-start corresponds to the top edge.
  • In vertical-rl, block-start corresponds to the right edge.
  • In vertical-lr, block-start corresponds to the left edge.
  • It adjusts scroll alignment without changing normal layout spacing.
  • It can improve anchor navigation when sticky headers obscure targets.
  • It can influence programmatic scrolling and CSS Scroll Snap alignment.
  • It does not create a scroll container or enable scroll snapping.
  • It does not control smooth scrolling animation.
  • The scroll-margin-block shorthand sets both logical block-axis scroll margins.
  • The scroll-margin-block-end property controls the opposite block edge.
  • The scroll-padding-block-start property defines container-side alignment spacing.
  • Physical and logical scroll margins can affect the same underlying edge.
  • The available scroll range can limit the final alignment position.
  • Responsive headers may require different scroll offsets at different viewport sizes.
  • Test keyboard navigation, zoom levels, writing modes, and reduced-motion preferences.

Browser Support

The CSS scroll-margin-block-start property is Baseline Widely available and is supported in current versions of major browsers.

Older browsers may have more limited support for logical scroll margin properties. The visible alignment can also depend on the scrolling operation and available scroll range.

For current compatibility information, visit Can I Use? and search for scroll-margin-block-start.

When unsupported, scrolling generally remains functional, but the additional block-start alignment offset may not be applied.

Specifications

The scroll-margin-block-start property is defined in CSS Scroll Snap Module Level 1.

CSS Scroll Snap Module Level 1

The specification defines logical scroll margin properties and their role in determining the scroll snap area surrounding a target.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: scroll-margin-block-start