Tillitsdone
down Scroll to discover

Master CSS scroll-margin-inline-end for Smooth Scrolling

Learn to use CSS scroll-margin-inline-end for smooth scrolling.

This property controls the scroll snap margin at the end of the inline dimension.

Discover length and global values.
thumbnail

The scroll-margin-inline-end Property in CSS

The scroll-margin-inline-end property in CSS is a great tool for web developers and designers. It helps control the scroll snap margin at the end of the inline dimension, making it easier to create smooth and responsive scrolling effects. This feature has been widely supported across browsers since July 2019, ensuring compatibility with a broad range of devices.

How It Works

The scroll-margin-inline-end property defines the margin of the scroll snap area at the end of the inline dimension. This property is crucial for snapping an element to the snapport, creating smooth and controlled scrolling effects. The scroll snap area is determined by the transformed border box, and the specified outsets are added to this box.

Syntax

You can specify the margin using length values such as pixels (px), em, rem, etc. Additionally, you can use global values like inherit, initial, revert, revert-layer, and unset to control the property’s behavior.

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

Values

The scroll-margin-inline-end property can take several values, providing flexibility for different design needs.

Length Values

The primary value for scroll-margin-inline-end is a length unit. This can be specified using various units such as pixels (px), em, rem, vh, etc.

scroll-margin-inline-end: 10px;
scroll-margin-inline-end: 1em;

Global Values

In addition to length values, scroll-margin-inline-end supports global CSS values that provide more control over inheritance and default behavior.

  • inherit: Inherits the value from the parent element.
  • initial: Sets the property to its default value.
  • revert: Resets the property to the browser’s default value.
  • revert-layer: Resets the property to the value established by the user-agent stylesheet.
  • unset: Resets the property to its natural value, which means it acts like inherit if the property is inherited, or like initial if it is not.
scroll-margin-inline-end: inherit;
scroll-margin-inline-end: initial;
scroll-margin-inline-end: revert;
scroll-margin-inline-end: revert-layer;
scroll-margin-inline-end: unset;

Formal Definition

The scroll-margin-inline-end property in CSS is formally defined to control the margin of the scroll snap area at the end of the inline dimension. This definition includes several key attributes that outline its behavior and usage.

  • Initial Value: 0
  • Applies To: All elements
  • Inherited: No
  • Computed Value: As specified
  • Animation Type: By computed value type

Examples

Let’s look at a practical example. We’ll create a horizontally scrolling container with several blocks and set different scroll margins for some of the blocks to demonstrate how they snap into place.

HTML

<div class="scroller">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>

CSS

.scroller {
width: 250px;
height: 250px;
overflow-x: scroll;
display: flex;
box-sizing: border-box;
border: 1px solid #000;
scroll-snap-type: x mandatory;
}
.scroller > div {
flex: 0 0 250px;
width: 250px;
background-color: #663399;
color: #fff;
font-size: 30px;
display: flex;
align-items: center;
justify-content: center;
scroll-snap-align: end;
}
.scroller > div:nth-child(2n) {
background-color: #fff;
color: #663399;
}
.scroller > div:nth-child(2) {
scroll-margin-inline-end: 1rem;
}
.scroller > div:nth-child(3) {
scroll-margin-inline-end: 2rem;
}

In this example, the blocks will snap into place near but not quite at the right edge of each block, as specified by the scroll-margin-inline-end values.

Specifications

The scroll-margin-inline-end property is defined in the CSS Scroll Snap Module Level 1 specification. This specification outlines the behavior and usage of scroll snap properties, including scroll-margin-inline-end.

Browser Compatibility

The scroll-margin-inline-end property is widely supported across modern browsers, making it a reliable choice for web developers and designers. This feature has been available since July 2019, ensuring compatibility with a broad range of devices and browser versions.

Supported Browsers

  • Google Chrome: Supported since version 69.
  • Microsoft Edge: Supported since version 79.
  • Firefox: Supported since version 68.
  • Opera: Supported since version 56.
  • Safari: Supported since version 14.1.

Compatibility Table

BrowserVersion
Google Chrome69
Microsoft Edge79
Firefox68
Opera56
Safari14.1

For more detailed information on browser compatibility, you can refer to the compatibility table provided below.

Reporting Issues

If you encounter any issues or have feedback on the scroll-margin-inline-end property, you can report it to help improve its documentation and support.

See Also

If you found this article helpful, you might also be interested in exploring related CSS properties and concepts:

CSS Scroll Snap

  • CSS Scroll Snap: Learn more about the CSS Scroll Snap module, which provides a comprehensive set of properties to control scroll snapping behavior.

Controlled Scrolling

Other CSS Properties

  • [scroll-margin-inline-start]WebsiteUrl: Similar to scroll-margin-inline-end, but applies to the start of the inline dimension.
  • [scroll-margin-block-end]WebsiteUrl: Applies to the end of the block dimension.
  • [scroll-margin-block-start]WebsiteUrl: Applies to the start of the block dimension.

CSS Properties

  • [scroll-padding-inline-end]WebsiteUrl: Adds padding at the end of a scrollable element’s inline dimension.
  • [scroll-snap-type]WebsiteUrl: Defines how scroll snapping works, whether it is mandatory or based on proximity.
  • [scroll-snap-align]WebsiteUrl: Sets the alignment of the scroll container’s snapport with the snap area.

Web Development Resources

  • [MDN Web Docs]WebsiteUrl: Offers comprehensive guides on HTML, CSS, JavaScript, and more.
  • [CSS-Tricks]WebsiteUrl: Stay updated on the latest CSS techniques and best practices.

Community and Support

  • [Stack Overflow]WebsiteUrl: Ask questions, share knowledge, and get help from fellow developers.
  • [Reddit - webdev]WebsiteUrl: Discuss trends, share projects, and get feedback from the web development community.

Exploring these resources will help you improve your CSS skills and connect with the developer community.

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.