CSS Properties
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.
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
Value | Description |
---|---|
length | Defines a fixed padding space at the bottom. Example: 20px, 2em. |
percentage | Defines 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.
<!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:
Author
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
If you have any doubts regarding this article (CSS scroll-padding-bottom Property), please comment here. I will help you immediately.