Tillitsdone
down Scroll to discover

CSS scroll-margin-bottom Enhance Scrolling Experience

Learn about CSS scroll-margin-bottom, a property that enhances scrolling experiences by defining the bottom margin of the scroll snap area.

Discover available options and how to use them effectively.
thumbnail

Introduction

The scroll-margin-bottom property in CSS is a handy tool for web developers and designers. It allows you to control the scroll snap area of an element precisely. This property defines the bottom margin of the scroll snap area, helping elements align perfectly within the scroll container. It’s been widely supported across browsers since July 2019, so you can use it confidently.

Specification

The scroll-margin-bottom property is defined in the CSS Scroll Snap Module Level 1 specification. This module helps control scroll snap points, making it easier to create smooth and precise scrolling experiences.

Description

The scroll-margin-bottom property in CSS sets the bottom margin of the scroll snap area for an element. This margin determines how much space should be added to the bottom edge of the element when it is snapped into position within the scroll container. By adjusting this property, you can ensure that elements snap into place perfectly, enhancing the visual appeal and user interaction of your web pages.

Syntax

The syntax for using the scroll-margin-bottom property is straightforward:

/* <length> values */
scroll-margin-bottom: 10px;
scroll-margin-bottom: 1em;
/* Global values */
scroll-margin-bottom: inherit;
scroll-margin-bottom: initial;
scroll-margin-bottom: revert;
scroll-margin-bottom: revert-layer;
scroll-margin-bottom: unset;

Values

The scroll-margin-bottom property accepts the following values:

  • <length>: Specifies the outset from the bottom edge of the scroll container. You can use various length units like px, em, rem, and vh.
  • Global Values: Include standard CSS values like inherit, initial, revert, revert-layer, and unset.

Note that scroll-margin-bottom does not accept percentage values.

Formal Definition

Initial value0
Applies toall elements
Inheritedno
Computed valueas specified
Animation typeby computed value type

Formal Syntax

scroll-margin-bottom = <length>

Example

Here’s a practical example to illustrate how the scroll-margin-bottom property works:

<!DOCTYPE html>
<html>
<head>
<style>
.scroller {
width: 300px;
height: 300px;
overflow-x: hidden;
overflow-y: auto;
scroll-snap-type: y mandatory;
}
.scroller > div {
width: 300px;
height: 300px;
font-size: 50px;
color: white;
display: flex;
align-items: center;
justify-content: center;
scroll-snap-align: end none;
}
.scroller div:nth-child(odd) {
background-color: green;
scroll-margin-bottom: 1rem;
}
.scroller div:nth-child(even) {
background-color: rgb(160, 231, 45);
scroll-margin-bottom: 3rem;
}
</style>
</head>
<body>
<div class="scroller">
<div>Geeks</div>
<div>for</div>
<div>Geeks</div>
<div>for</div>
<div>Geeks</div>
</div>
</body>
</html>

Supported Browsers

The scroll-margin-bottom property is supported in the following browsers:

  • Google Chrome 69
  • Edge 79
  • Firefox 68
  • Opera 56
  • Safari 14.1

See Also

For more information on CSS scroll snap and related properties, you can refer to:

  • [CSS scroll snap]WebsiteUrl
  • [Well-controlled scrolling with CSS scroll snap]WebsiteUrl
  • [scroll-margin-top]WebsiteUrl
  • [scroll-margin-left]WebsiteUrl
  • [scroll-margin-right]WebsiteUrl

By understanding and utilizing scroll-margin-bottom, you can create more engaging and user-friendly web experiences. Happy coding!

icons/css-4.svg CSS Blogs
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.