CSS scroll-margin-block-end Property

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

It adjusts the area used to align an element during scrolling without changing its layout spacing. The block-end edge depends on the element's writing mode, so the property can adapt to horizontal and vertical text layouts.

scroll-margin-block-end Syntax

The scroll-margin-block-end property accepts a single CSS length value.

Basic Syntax

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

Available Values

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

CSS-Wide Keywords

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

The property accepts positive, zero, and negative length values. Percentages and the auto keyword are not valid.

Property Values

Value Description
<length> Specifies the scroll margin at the logical block-end edge using a CSS length.
0 Applies no additional block-end scroll margin. This is the initial value.
Positive length Expands the scroll alignment area beyond the block-end edge.
Negative length Contracts the scroll alignment area at the block-end edge.
calc() Calculates a valid length using a 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-end: 30px;
}
.target {
  scroll-margin-block-end: 2rem;
}
.target {
  scroll-margin-block-end: 0;
}
.target {
  scroll-margin-block-end: -5px;
}
.target {
  scroll-margin-block-end: calc(20px + 1rem);
}

Invalid Values

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

Only a single length value or a CSS-wide keyword is valid. The property does not accept percentages, multiple lengths, time values, or scrolling behavior keywords.

How It Works

The scroll-margin-block-end property adjusts the scroll alignment area beyond an element's logical block-end edge.

When the browser calculates a scroll position for the element, this additional margin can influence where the target is aligned within the scrolling container.

Default Value

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

No additional scroll alignment space is applied at block-end.

Positive Scroll Margin

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

The target's scroll alignment area extends 40 pixels beyond its block-end edge.

Negative Scroll Margin

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

The scroll alignment area contracts by 10 pixels at block-end.

No Layout Changes

The property does not add space between elements, change their dimensions, or alter normal document flow.

Alignment Depends on the Scroll Operation

The visible result depends on the requested alignment, the scrolling container, and the available scroll range. A block-end margin is particularly useful when aligning the end of a target with the end of a scrollport.

Important Distinction

Scroll margin changes the area used for alignment, not the element's actual layout position. It also does not create a scroll container or control scrolling animation.

Writing Modes and Block-End Direction

The logical block-end edge depends on the element's writing-mode value.

Horizontal Writing Mode

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

In horizontal-tb, block-end corresponds to the bottom edge.

Vertical Right-to-Left Writing Mode

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

In vertical-rl, block-end corresponds to the left edge.

Vertical Left-to-Right Writing Mode

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

In vertical-lr, block-end corresponds to the right edge.

Writing Mode Reference

Writing Mode Block-End Edge
horizontal-tb Bottom
vertical-rl Left
vertical-lr Right

Text Direction

The direction property controls inline text progression but does not independently reverse the block-end edge in horizontal writing.

Important Consideration

Logical scroll margins help layouts adapt to different writing modes without replacing physical top, bottom, left, or right declarations manually.

Scroll Target Alignment

The scroll-margin-block-end property is especially useful when an element is aligned near the block-end edge of a scrolling container.

Aligning a Target With JavaScript

document.querySelector("#target").scrollIntoView({
  block: "end",
  behavior: "smooth"
});

The block: "end" option requests alignment of the target near the block-end edge of its scrolling container.

Adding Block-End Scroll Margin

#target {
  scroll-margin-block-end: 50px;
}

The browser can account for the 50-pixel scroll margin when aligning the target at block-end.

Using Normal Scrolling

document.querySelector("#target").scrollIntoView({
  block: "end",
  behavior: "instant"
});

JavaScript supports an instant scrolling behavior, even though instant is not a valid CSS scroll-behavior value.

Available Scroll Range

A target near the beginning or end of a scroll container may not reach the requested alignment if the container cannot scroll far enough.

Important Consideration

The property does not force block-end alignment. It adjusts the target's alignment area when a scrolling operation uses that edge.

Scroll Snapping

CSS Scroll Snap can use scroll-margin-block-end to adjust the snap area around an individual target.

Vertical Scroll Snap Example

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

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

Using Different Block Margins

.scroll-panel .item {
  scroll-margin-block-start: 10px;
  scroll-margin-block-end: 40px;
}

The target receives different scroll margins at its block-start and block-end edges.

Combining With scroll-padding-block-end

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

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

Important Consideration

The property does not enable scroll snapping. The container needs an appropriate scroll-snap-type declaration, and the target needs a scroll-snap-align value.

Anchor Navigation

Scroll margins can also influence the alignment of targets reached through anchor navigation.

HTML Example

<nav aria-label="Page sections">
  <a href="#overview">Overview</a>
  <a href="#examples">Examples</a>
</nav>
<section id="overview">
  <h2>Overview</h2>
  <p>Overview content.</p>
</section>
<section id="examples">
  <h2>Examples</h2>
  <p>Example content.</p>
</section>

CSS Example

section[id] {
  scroll-margin-block-end: 30px;
}

The block-end margin expands the scroll alignment area around each section. The visible offset depends on how the browser aligns the anchor target.

Sticky Headers

For a sticky header at the top of a page using horizontal writing, scroll-margin-block-start is generally more useful because block-start corresponds to the top edge.

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

When Block-End Is Useful

Block-end scroll margin is useful when a target needs additional space near the bottom of a horizontal scrollport or the corresponding logical edge in vertical writing.

Important Consideration

Anchor navigation does not guarantee block-end alignment. For precise alignment, a scrolling API such as scrollIntoView() can specify the intended block position.

Using the scroll-margin-block Shorthand

The scroll-margin-block shorthand sets both logical block-axis scroll margins.

Shorthand Declaration

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

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

Equivalent Longhand Declarations

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

One Shorthand Value

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

Both block edges receive 30 pixels of scroll margin.

Overriding Block-End

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

The block-start value remains 20 pixels, while block-end becomes 60 pixels.

Declaration Order

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

The later shorthand resets both block margins to 20 pixels.

Important Consideration

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

Logical Versus Physical Scroll Margins

Logical scroll margin properties follow writing modes, while physical scroll margin properties always refer to fixed sides.

Property Edge
scroll-margin-block-end Logical block-end edge
scroll-margin-bottom Physical bottom edge
scroll-margin-left Physical left edge
scroll-margin-right Physical right edge

Physical Bottom Scroll Margin

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

The bottom scroll margin remains 40 pixels regardless of writing mode.

Logical Block-End Scroll Margin

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

The scroll margin applies to the block-end edge determined by the writing mode.

Equivalent Values in Horizontal Writing

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

In horizontal writing, this is equivalent to setting scroll-margin-bottom: 40px.

Important Consideration

Physical and logical declarations can target the same edge. Normal CSS cascade rules determine which value applies when declarations overlap.

scroll-margin-block-end Versus scroll-padding-block-end

Both properties affect block-end scroll alignment, but they apply to different parts of the scrolling relationship.

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

Target-Side Offset

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

Container-Side Offset

.scroll-container {
  scroll-padding-block-end: 40px;
}

Combining Both Properties

.scroll-container {
  scroll-padding-block-end: 20px;
}
.scroll-container .target {
  scroll-margin-block-end: 30px;
}

Both offsets can influence the final alignment of a target near the block-end edge.

When to Use Each Property

Use scroll-padding-block-end for a consistent container-side offset. Use scroll-margin-block-end when an individual target needs additional block-end spacing.

scroll-margin-block-end Example

The following example compares two scrollable panels. Both align a target near the bottom, but the second panel applies a 40-pixel block-end scroll margin.

HTML Example

<div class="scroll-end-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-End 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-end-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}
.scroll-end-demo .scroll-panel {
  height: 180px;
  overflow-y: auto;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
}
.scroll-end-demo .spacer {
  height: 200px;
  padding: 15px;
  box-sizing: border-box;
}
.scroll-end-demo .target {
  padding: 15px;
  background-color: #bfdbfe;
  border: 2px solid #2563eb;
}
.scroll-end-demo .with-margin .target {
  scroll-margin-block-end: 40px;
}
.scroll-end-demo button {
  margin-top: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
@media (prefers-reduced-motion: reduce) {
  .scroll-end-demo .scroll-panel {
    scroll-behavior: auto;
  }
}

JavaScript Example

document.querySelectorAll(".scroll-end-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: "end"
    });
  });
});
Browser Result

Without Scroll Margin

Scroll content
Target Element
More content

With Block-End Scroll Margin

Scroll content
Target Element
More content

Click the button beneath each panel. The first target aligns near the bottom edge of its scroll container. The second target uses a 40-pixel block-end scroll margin, leaving additional space below it.

Increasing the Offset

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

The target requests a larger block-end alignment offset.

Removing the Offset

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

The additional block-end alignment space is removed.

Browser Compatibility Note

Scroll alignment can vary according to browser behavior and available scroll range. The target may not reach the requested position if the scroll container cannot move far enough.

Accessibility Considerations

Scroll margins can improve navigation by helping users see the intended target without changing document layout or reading order.

Keep Targets Visible

Use appropriate offsets when interface elements overlap the block-end edge of a scrolling container.

Support Different Writing Modes

Logical scroll margins adapt to the writing direction of the content, making them useful for multilingual layouts.

Maintain Keyboard Accessibility

Buttons and links that initiate scrolling should remain keyboard accessible and display visible focus indicators.

Consider Focus Management

Scrolling an element into view does not always move keyboard focus to it. Scripted navigation may require additional focus handling.

Avoid Excessive Offsets

Large scroll margins can position targets unexpectedly far from the edge of the viewport or scrolling container.

Respect Reduced Motion Preferences

The property does not animate scrolling, but it is often combined with smooth scrolling. Respect prefers-reduced-motion when adding animated navigation.

Test Responsive Layouts

Check scroll alignment at different viewport sizes and zoom levels, especially when fixed interface elements change dimensions.

Important Consideration

Scroll margins affect visual alignment only. They do not replace semantic navigation, accessible controls, or appropriate focus management.

Common Mistakes

Using Percentage Values

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

Percentages are not valid. Use a CSS length instead.

Using auto

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

The property does not accept the auto keyword.

Providing Multiple Lengths

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

This longhand property accepts only one length value.

Confusing Block-End With Bottom

Block-end corresponds to the bottom only in horizontal writing. In vertical writing, it corresponds to the left or right edge.

Expecting Layout Spacing

Scroll margin does not add normal spacing between neighboring elements.

Applying the Property to the Scroll Container

Use scroll-margin-block-end on the scroll target. Use scroll-padding-block-end on the container for a container-side offset.

Expecting Scroll Snapping Automatically

Scroll margin does not enable snapping. Scroll snapping requires appropriate container and target properties.

Using Block-End for a Top Sticky Header

In horizontal writing, a top sticky header is generally handled with scroll-margin-block-start, not block-end.

Ignoring Declaration Order

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

Expecting Identical Browser Alignment

The final scroll position depends on the scrolling operation, available scroll range, and browser implementation.

Important Considerations

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

  • It is a logical scroll margin longhand property.
  • It sets the scroll margin at the logical block-end edge.
  • Its initial value is 0.
  • The property is not inherited.
  • It applies to all elements.
  • It accepts a single CSS length value.
  • Positive and negative lengths are valid.
  • Percentage values are invalid.
  • The auto keyword is invalid.
  • The block-end edge depends on the writing mode.
  • In horizontal-tb, block-end is the bottom edge.
  • In vertical-rl, block-end is the left edge.
  • In vertical-lr, block-end is the right edge.
  • It adjusts the scroll alignment area around the target.
  • It does not change normal layout spacing.
  • It does not directly move an element.
  • It can influence anchor navigation and programmatic scrolling.
  • It can adjust scroll snap alignment.
  • It does not enable scroll snapping by itself.
  • It does not create a scroll container.
  • It does not control smooth scrolling animation.
  • The scroll-margin-block shorthand sets both block-axis margins.
  • The scroll-margin-block-start property controls the opposite logical block edge.
  • The scroll-padding-block-end property defines a container-side offset.
  • Physical and logical declarations can affect the same underlying edge.
  • Normal CSS cascade rules determine which overlapping declaration applies.
  • The available scroll range can limit the final alignment position.
  • Logical properties help support different writing modes.
  • Scroll offsets should accommodate responsive interface dimensions.
  • Scroll margins do not replace appropriate focus management.
  • Test scrolling behavior across browsers, writing modes, and viewport sizes.

Browser Support

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

Support may be more limited in older browsers, particularly for logical scroll margin properties. The visible effect 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-end.

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

Specifications

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

CSS Scroll Snap Module Level 1

The specification defines logical scroll margin properties and how scroll margins affect the scroll snap area surrounding a target.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: scroll-margin-block-end