CSS Portal

CSS scroll-margin-bottom Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The scroll-margin-bottom property defines an extra offset applied to an element when the user (or script) scrolls that element into view. Rather than changing the element’s layout or the flow of the document, it influences where the element is positioned relative to the bottom edge of the scroll container after the scrolling finishes. This makes it useful for ensuring the target of an anchor link, a programmatic scroll, or a keyboard focus becomes visible with some breathing room rather than sitting flush against the container edge.

Because the offset is applied at scroll time, the property is set on the element being targeted rather than on the scrolling container. It therefore behaves quite differently from layout-level spacing such as margin-bottom; adding a scroll margin does not affect surrounding content, element collapse, or reflow—only the final scrolled position. This distinction is why developers often use scroll margin to tweak in-view placement for interactive focus targets, “skip to content” links, and fragment navigation without altering the page’s visual layout.

This property interacts with other scroll-related controls. For example, when you combine it with CSS scroll snapping, the snap calculations take an element’s scroll margins into account alongside its snap alignment so that snapped positions land where you intend; see scroll-snap-align for how element alignment participates in snapping. For container-side adjustments—creating a persistent inset or “safe area” inside a scroll container—use the container-focused control scroll-padding; the final scrolled position is determined considering both the container’s padding and the element’s scroll margin.

In practical terms, scroll-margin-bottom is a simple but powerful tool for improving usability: it prevents important content from being obscured by fixed headers, gives visual context when jumping to anchors, and helps make keyboard or programmatic navigation feel less abrupt. It applies uniformly to user-initiated and script-initiated scrolling, and because it does not alter layout, it is safe to add to targets where you only want to influence scrolling behavior without impacting surrounding element placement.

Definition

Initial value
0
Applies to
all elements
Inherited
no
Computed value
as specified
Animatable
by computed value type
JavaScript syntax
object.style.scrollMarginBottom

Interactive Demo

1
2
3
Scroll »

Syntax

scroll-margin-bottom: <length>

Values

  • <length>An outset from the bottom edge of the scroll container.

Example

<body>
<nav class='toc'>
<a href='#section1'>Section 1</a>
<a href='#section2'>Section 2</a>
<a href='#section3'>Section 3</a>
</nav>

<main>
<section id='section1' class='content-section'>
<h2>Section 1</h2>
<p>Content for section 1. Scroll or click the links to see scroll-margin-bottom in action.</p>
</section>

<section id='section2' class='content-section'>
<h2>Section 2</h2>
<p>Content for section 2. The heading has a scroll-margin-bottom equal to the footer height.</p>
</section>

<section id='section3' class='content-section'>
<h2>Section 3</h2>
<p>Content for section 3. Try clicking links while the footer is visible.</p>
</section>
</main>

<footer class='fixed-footer'>Fixed footer - height: 64px</footer>
</body>
:root {
  --footer-height: 64px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
  line-height: 1.4;
}

.toc {
  position: sticky;
  top: 0;
  background: #fff;
  padding: 1rem;
  border-bottom: 1px solid #eee;
  z-index: 10;
}

.toc a {
  margin-right: 1rem;
  color: #0366d6;
  text-decoration: none;
}

main {
  padding: 2rem 1rem 8rem; /* extra bottom padding so content can scroll above footer */
}

.content-section {
  padding: 3rem 0;
  border-bottom: 1px solid #f5f5f5;
}

.content-section h2 {
  margin: 0 0 1rem 0;
  /* Ensure the heading scrolls above the fixed footer */
  scroll-margin-bottom: var(--footer-height);
}

.fixed-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--footer-height);
  background: #222;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
}

html {
  scroll-behavior: smooth;
}

Browser Support

The following information will show you the current browser support for the CSS scroll-margin-bottom property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!