CSS scroll-margin-bottom Property

The CSS scroll-margin-bottom property sets the scroll margin at the physical bottom edge of an element.

It extends or contracts the area used to align a target during scrolling without changing its actual layout spacing. The property is useful for scroll snapping, programmatic scrolling, and keeping targets clear of controls positioned near the bottom of a scroll container.

scroll-margin-bottom Syntax

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

Basic Syntax

selector {
  scroll-margin-bottom: 20px;
}

Available Values

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

CSS-Wide Keywords

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

Positive values expand the target's scroll alignment area below its bottom edge. Negative values contract that area. Percentages and auto are invalid.

Property Values

Value Description
<length> Sets the bottom scroll margin using a CSS length such as px, rem, or em.
0 Applies no additional bottom scroll margin. This is the initial value.
Positive length Expands the scroll alignment area beyond the bottom edge.
Negative length Contracts the scroll alignment area at the bottom edge.
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-bottom: 40px;
}
.target {
  scroll-margin-bottom: 3rem;
}
.target {
  scroll-margin-bottom: 0;
}
.target {
  scroll-margin-bottom: -5px;
}
.target {
  scroll-margin-bottom: calc(2rem + 15px);
}

Invalid Values

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

The property accepts a single length, not percentages, multiple values, time units, or scrolling behavior keywords.

How It Works

The scroll-margin-bottom property changes the scroll alignment area surrounding a target by extending or contracting its bottom edge.

The browser can use this adjusted area when determining where to position the target during scroll snapping or programmatic scrolling.

Default Bottom Scroll Margin

.target {
  scroll-margin-bottom: 0;
}

The target receives no additional bottom scroll alignment space.

Positive Bottom Scroll Margin

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

The scroll alignment area extends 40 pixels below the target's bottom edge.

Negative Bottom Scroll Margin

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

The scroll alignment area contracts by 10 pixels at the bottom edge.

Layout Space Is Unchanged

Unlike margin-bottom, this property does not add normal layout space below an element or push neighboring elements farther apart.

Available Scroll Range

The requested alignment may be limited by the scroll container's available range. A target near the beginning or end of a container may not reach the preferred position.

Important Distinction

Scroll margin affects alignment calculations, not the element's actual dimensions or normal document position.

Scroll Target Alignment

The bottom scroll margin is especially useful when a scrolling operation aligns the bottom of a target with the bottom of its scroll container.

JavaScript Alignment Example

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

The block: "end" option requests alignment at the logical block-end edge. In horizontal writing, this corresponds to bottom alignment.

Adding Bottom Scroll Margin

#target {
  scroll-margin-bottom: 50px;
}

When the target is aligned at the bottom of a horizontal scrollport, the additional margin can leave space below it.

Using Instant Scrolling

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

The JavaScript instant behavior requests immediate scrolling. The CSS scroll margin still affects the target's alignment area.

Alignment in Vertical Writing Modes

The physical bottom margin always applies to the bottom edge. However, block: "end" follows the writing mode, so it does not necessarily align the physical bottom edge in vertical writing.

Important Consideration

The property does not force a particular scroll alignment. It provides an offset that the browser can use during the selected scrolling operation.

Scroll Snapping

The scroll-margin-bottom property can adjust the snap area of an element during CSS Scroll Snap alignment.

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-bottom: 30px;
}

The snap area extends 30 pixels below each item, affecting how the item aligns near the bottom of the scroll container.

Different Margins for Individual Targets

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

The featured item receives a larger bottom scroll margin.

Combining With Scroll Padding

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

Scroll padding defines an inset inside the container, while scroll margin extends the target's snap area.

Important Consideration

The property does not enable scroll snapping. The scroll container must define scroll-snap-type, and the targets must have an appropriate scroll-snap-align value.

Using the scroll-margin Shorthand

The scroll-margin shorthand sets the physical scroll margins on all four sides of an element.

Four-Value Shorthand

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

The values correspond to top, right, bottom, and left. The bottom scroll margin is 40 pixels.

Equivalent Longhand Declarations

.target {
  scroll-margin-top: 10px;
  scroll-margin-right: 20px;
  scroll-margin-bottom: 40px;
  scroll-margin-left: 30px;
}

One-Value Shorthand

.target {
  scroll-margin: 20px;
}

All four physical edges receive 20 pixels of scroll margin.

Two-Value Shorthand

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

The top and bottom receive 20 pixels, while the left and right receive 40 pixels.

Three-Value Shorthand

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

The top receives 10 pixels, the left and right receive 20 pixels, and the bottom receives 40 pixels.

Overriding the Bottom Edge

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

The bottom scroll margin becomes 60 pixels while the other three edges remain at 20 pixels.

Declaration Order

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

The later shorthand resets all four scroll margins to 20 pixels.

Physical Versus Logical Scroll Margins

The scroll-margin-bottom property always refers to the physical bottom edge. Logical scroll margin properties follow the element's writing mode.

Property Edge
scroll-margin-bottom Physical bottom edge
scroll-margin-block-end Logical block-end edge
scroll-margin-block-start Logical block-start edge
scroll-margin-inline-end Logical inline-end edge

Horizontal Writing Mode

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

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

Vertical Writing Mode

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

The property still applies to the physical bottom edge, even though the block axis runs horizontally.

Logical Alternative

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

This declaration follows the logical block-end edge, which may be the bottom, left, or right edge depending on the writing mode.

Important Consideration

Use physical scroll margins when an offset must remain attached to a fixed side. Use logical scroll margins when the offset should adapt to the writing mode.

scroll-margin-bottom Versus scroll-padding-bottom

Both properties affect bottom-edge scroll alignment, but they apply to different elements.

Property Applied To Purpose
scroll-margin-bottom Scroll target Expands or contracts the target's alignment area below its bottom edge.
scroll-padding-bottom Scroll container Defines an inset at the bottom of the container's optimal viewing region.

Target-Side Offset

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

Container-Side Offset

.scroll-container {
  scroll-padding-bottom: 40px;
}

Combining Both Properties

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

Both offsets can influence the target's final alignment near the bottom of the scroll container.

When to Use Each Property

Use scroll-padding-bottom for a consistent container-side offset. Use scroll-margin-bottom when individual scroll targets need additional space below them.

scroll-margin-bottom Example

This example compares two scrollable panels. Both contain a target that can be aligned near the bottom, but the second target has an additional 40-pixel bottom scroll margin.

HTML Example

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

JavaScript Example

document.querySelectorAll(".scroll-bottom-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 Bottom Scroll Margin

Scroll content
Target Element
More content

Click the button beneath each panel. In horizontal writing, the first target aligns near the bottom of its scroll container. The second leaves approximately 40 pixels below the target because of its bottom scroll margin.

Increasing the Bottom Offset

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

The target requests a larger bottom alignment offset.

Removing the Offset

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

The additional bottom scroll alignment space is removed.

Browser Compatibility Note

The final scroll position can depend on the browser, the scrolling operation, and the available scroll range. Targets near the boundaries of a scroll container may not reach their requested alignment.

Accessibility Considerations

Bottom scroll margins can help keep important targets visible when a scrolling interface includes controls or overlays near its lower edge.

Keep Content Visible

Use appropriate offsets when fixed or sticky interface elements could obscure the bottom of a scroll target.

Maintain Keyboard Accessibility

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

Consider Focus Management

Programmatically scrolling an element into view does not necessarily move keyboard focus. Additional focus management may be needed for scripted navigation.

Respect Reduced Motion Preferences

The property does not animate scrolling. If smooth scrolling is also used, account for the user's prefers-reduced-motion setting.

Avoid Excessive Offsets

Large bottom scroll margins may leave unnecessary space below targets or prevent them from reaching their preferred alignment position.

Test Responsive Layouts

Verify that offsets remain useful at different viewport sizes, zoom levels, and interface configurations.

Important Consideration

Scroll margins improve visual alignment but do not change semantic structure, reading order, or keyboard focus behavior.

Common Mistakes

Using Percentage Values

.target {
  scroll-margin-bottom: 10%;
}

Percentages are invalid. Use a CSS length instead.

Using auto

.target {
  scroll-margin-bottom: auto;
}

The property does not accept auto.

Providing Multiple Values

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

This longhand property accepts only one length value.

Confusing Scroll Margin With Layout Margin

.target {
  margin-bottom: 40px;
}

The margin-bottom property changes layout spacing. The scroll-margin-bottom property changes scroll alignment calculations.

Applying the Property to the Wrong Element

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

Expecting Automatic Scroll Snapping

The property does not enable scroll snapping by itself.

Confusing Physical and Logical Edges

The bottom edge remains the physical bottom regardless of writing mode. Use a logical property when the offset should follow the text layout.

Ignoring Declaration Order

A later scroll-margin shorthand can override an earlier scroll-margin-bottom declaration.

Expecting Smooth Scrolling

The property does not control scrolling animation. Use scroll-behavior or the appropriate scrolling API options for that purpose.

Important Considerations

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

  • It sets the scroll margin at the physical bottom edge of an element.
  • Its initial value is 0, and it is not inherited.
  • It accepts one CSS length value, including negative lengths.
  • Percentages and auto are invalid.
  • It applies to all elements, although its visible effect depends on scrolling behavior.
  • It expands or contracts the target's scroll alignment area.
  • It does not add layout space or change element dimensions.
  • It can influence programmatic scrolling and scroll snapping.
  • It does not create a scroll container or enable scroll snapping.
  • It does not control smooth scrolling.
  • The scroll-margin shorthand sets all four physical scroll margins.
  • The scroll-margin-block-end property is a logical alternative when the block-end edge should follow the writing mode.
  • The scroll-padding-bottom property defines a container-side offset.
  • The available scroll range can limit the final alignment position.
  • Normal CSS cascade rules apply when shorthand, longhand, and logical declarations overlap.
  • Test scrolling behavior at different viewport sizes and writing modes.

Browser Support

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

Older browsers may have limited support. The visible result can also vary according to the scrolling operation and available scroll range.

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

When unsupported, scrolling generally remains functional, but the additional bottom scroll alignment offset may not be applied.

Specifications

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

CSS Scroll Snap Module Level 1

The specification describes how scroll margins expand or contract the scroll snap area surrounding an element.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: scroll-margin-bottom