Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS scroll-padding-bottom Property

Posted in CSS Tutorial
Updated on Oct 13, 2024
By Mari Selvan
👁️ 12 - Views
⏳ 4 mins
💬 1 Comment
CSS scroll-padding-bottom Property

Photo Credit to CodeToFun

🙋 Introduction

The scroll-padding-bottom property in CSS is part of the scroll-padding family of properties that allows you to control the padding of a scrolling container.

This property specifically sets the padding space at the bottom of the viewport when a scrollable element is scrolled. It's useful for creating a buffer area at the bottom of the viewport to ensure that content is not obscured or clipped during scrolling.

💡 Syntax

The syntax for the scroll-padding-bottom property is simple. You can specify a length or percentage to define the padding space.

Syntax
Copied
Copy To Clipboard
element {
  scroll-padding-bottom: length | percentage;
}

🎛️ Default Value

The default value of the scroll-padding-bottom property is 0. This means there is no additional padding space at the bottom of the viewport unless explicitly specified.

🏠 Property Values

ValueDescription
lengthDefines a fixed padding space at the bottom. Example: 20px, 2em.
percentageDefines a padding space relative to the height of the scroll container. Example: 10%.

📄 Example

In this example, we'll add padding space at the bottom of a scrollable container to ensure that the last item is not obscured when scrolled to the bottom.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS scroll-padding-bottom Example</title>
  <style>
    .scroll-container {
      height: 200px;
      overflow-y: scroll;
      scroll-padding-bottom: 20px; /* Adding space at the bottom */
    }
    .content {
      height: 600px;
      background: linear-gradient(to bottom, #ffcc00, #ff6600);
    }
  </style>
</head>
<body>
  <h1>Scrollable Container with Padding at the Bottom</h1>
  <div class="scroll-container">
    <div class="content">
      Scroll down to see the padding effect at the bottom.
    </div>
  </div>
</body>
</html>

🖥️ Browser Compatibility

The scroll-padding-bottom property is supported in modern browsers, including the latest versions of Chrome, Firefox, Safari, and Edge. It's important to test the behavior across different browsers to ensure consistent results.

🎉 Conclusion

The scroll-padding-bottom property is a valuable tool for enhancing user experience by preventing content from being obscured when a scrolling container is scrolled.

By setting appropriate padding values, you can ensure that users can always see the content clearly, particularly at the bottom of the viewport. Experiment with different padding values to find the best fit for your design needs.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy