CSS scroll-margin-bottom Property

Description

The scroll-margin-bottom CSS property is used to specify the minimum margin between the bottom edge of an element and the viewport when scrolling. It allows web developers to control the space left at the bottom of the viewport when an anchor link or fragment identifier is used to navigate to a specific part of a webpage. By setting this property, you can ensure that the content you're navigating to is appropriately spaced from the bottom of the viewport, improving the overall user experience and readability, especially when dealing with fixed headers or footers.

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

<div id="container">
<div class="blue"></div>
<div class="green"></div>
<div class="blue"></div>
<div class="green"></div>
<div class="blue"></div>
<div class="green"></div>
<div class="blue"></div>
</div>
#container {
  position: relative;
  width: 80%;
  aspect-ratio: 3/1;
  margin: auto;
  border: solid black 2px;
  overflow-x: hidden;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
}

.blue {
  background-color: lightblue;
  width: 95%;
  aspect-ratio: 3/1;
}

.green {
  background-color: lightgreen;
  width: 80%;
  aspect-ratio: 4/1;
}

.blue, .green {
  margin: 2px;
  scroll-snap-align: end;
  scroll-margin-bottom: 20px;
}

Browser Support

The following table will show you the current browser support for the CSS scroll-margin-bottom property.

Desktop
Edge Chrome Firefox Opera Safari
7969685614.1
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
69684814.51069

Last updated by CSSPortal on: 3rd January 2024