Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS scroll-margin-inline-end Property

Posted in CSS Tutorial
Updated on Oct 07, 2024
By Mari Selvan
👁️ 11 - Views
⏳ 4 mins
💬 1 Comment
CSS scroll-margin-inline-end Property

Photo Credit to CodeToFun

🙋 Introduction

The scroll-margin-inline-end property in CSS is used to set the margin at the end edge of the scroll container in the inline direction.

This property is particularly useful when you want to adjust the scroll position to ensure that the content is not too close to the edge of the viewport when it is brought into view.

💡 Syntax

The syntax for the scroll-margin-inline-end property is straightforward. You can specify the margin value using any valid CSS length unit.

Syntax
Copied
Copy To Clipboard
element {
  scroll-margin-inline-end: length;
}

Here, length can be a value in pixels (px), em units (em), rem units (rem), percentages (%), or any other valid CSS length unit.

🎛️ Default Value

The default value of the scroll-margin-inline-end property is 0. This means that, by default, there is no additional margin applied at the end edge of the scroll container.

🏠 Property Values

ValueDescription
lengthA specific length value, such as 10px, 2em, 1rem, etc.
percentageA percentage of the containing block's inline size, such as 10%.

📄 Example

In this example, we'll set the scroll-margin-inline-end property to 20px for a container.

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-margin-inline-end Example</title>
  <style>
    .container {
      width: 200px;
      height: 100px;
      overflow: auto;
      border: 1px solid black;
    }
    .item {
      width: 500px;
      height: 100px;
      background-color: lightblue;
      scroll-margin-inline-end: 20px;
    }
  </style>
</head>
<body>
  <h1>Scroll Margin Inline End Example</h1>
  <div class="container">
    <div class="item">Scroll me!</div>
  </div>
</body>
</html>

🖥️ Browser Compatibility

The scroll-margin-inline-end property is supported in most modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. However, it is always a good practice to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The scroll-margin-inline-end property is a useful tool for adjusting the scroll position of elements within a scroll container.

By setting an appropriate margin, you can ensure that content is displayed at a comfortable distance from the edge of the viewport, enhancing the overall user experience. Experiment with different margin values to see how this property can improve the layout and accessibility of your web projects.

👨‍💻 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