Interactivity
Scroll Margin
Utilities for controlling the scroll offset around items in a snap container.
Quick reference
Class | Properties |
---|---|
scroll-m-0 | scroll-margin: 0px; |
scroll-mx-0 | scroll-margin-left: 0px; scroll-margin-right: 0px; |
scroll-my-0 | scroll-margin-top: 0px; scroll-margin-bottom: 0px; |
scroll-mt-0 | scroll-margin-top: 0px; |
scroll-mr-0 | scroll-margin-right: 0px; |
scroll-mb-0 | scroll-margin-bottom: 0px; |
scroll-ml-0 | scroll-margin-left: 0px; |
scroll-m-px | scroll-margin: 1px; |
scroll-mx-px | scroll-margin-left: 1px; scroll-margin-right: 1px; |
scroll-my-px | scroll-margin-top: 1px; scroll-margin-bottom: 1px; |
scroll-mt-px | scroll-margin-top: 1px; |
scroll-mr-px | scroll-margin-right: 1px; |
scroll-mb-px | scroll-margin-bottom: 1px; |
scroll-ml-px | scroll-margin-left: 1px; |
scroll-m-0.5 | scroll-margin: 0.125rem; |
scroll-mx-0.5 | scroll-margin-left: 0.125rem; scroll-margin-right: 0.125rem; |
scroll-my-0.5 | scroll-margin-top: 0.125rem; scroll-margin-bottom: 0.125rem; |
scroll-mt-0.5 | scroll-margin-top: 0.125rem; |
scroll-mr-0.5 | scroll-margin-right: 0.125rem; |
scroll-mb-0.5 | scroll-margin-bottom: 0.125rem; |
scroll-ml-0.5 | scroll-margin-left: 0.125rem; |
scroll-m-1 | scroll-margin: 0.25rem; |
scroll-mx-1 | scroll-margin-left: 0.25rem; scroll-margin-right: 0.25rem; |
scroll-my-1 | scroll-margin-top: 0.25rem; scroll-margin-bottom: 0.25rem; |
scroll-mt-1 | scroll-margin-top: 0.25rem; |
scroll-mr-1 | scroll-margin-right: 0.25rem; |
scroll-mb-1 | scroll-margin-bottom: 0.25rem; |
scroll-ml-1 | scroll-margin-left: 0.25rem; |
scroll-m-1.5 | scroll-margin: 0.375rem; |
scroll-mx-1.5 | scroll-margin-left: 0.375rem; scroll-margin-right: 0.375rem; |
scroll-my-1.5 | scroll-margin-top: 0.375rem; scroll-margin-bottom: 0.375rem; |
scroll-mt-1.5 | scroll-margin-top: 0.375rem; |
scroll-mr-1.5 | scroll-margin-right: 0.375rem; |
scroll-mb-1.5 | scroll-margin-bottom: 0.375rem; |
scroll-ml-1.5 | scroll-margin-left: 0.375rem; |
scroll-m-2 | scroll-margin: 0.5rem; |
scroll-mx-2 | scroll-margin-left: 0.5rem; scroll-margin-right: 0.5rem; |
scroll-my-2 | scroll-margin-top: 0.5rem; scroll-margin-bottom: 0.5rem; |
scroll-mt-2 | scroll-margin-top: 0.5rem; |
scroll-mr-2 | scroll-margin-right: 0.5rem; |
scroll-mb-2 | scroll-margin-bottom: 0.5rem; |
scroll-ml-2 | scroll-margin-left: 0.5rem; |
scroll-m-2.5 | scroll-margin: 0.625rem; |
scroll-mx-2.5 | scroll-margin-left: 0.625rem; scroll-margin-right: 0.625rem; |
scroll-my-2.5 | scroll-margin-top: 0.625rem; scroll-margin-bottom: 0.625rem; |
scroll-mt-2.5 | scroll-margin-top: 0.625rem; |
scroll-mr-2.5 | scroll-margin-right: 0.625rem; |
scroll-mb-2.5 | scroll-margin-bottom: 0.625rem; |
scroll-ml-2.5 | scroll-margin-left: 0.625rem; |
scroll-m-3 | scroll-margin: 0.75rem; |
scroll-mx-3 | scroll-margin-left: 0.75rem; scroll-margin-right: 0.75rem; |
scroll-my-3 | scroll-margin-top: 0.75rem; scroll-margin-bottom: 0.75rem; |
scroll-mt-3 | scroll-margin-top: 0.75rem; |
scroll-mr-3 | scroll-margin-right: 0.75rem; |
scroll-mb-3 | scroll-margin-bottom: 0.75rem; |
scroll-ml-3 | scroll-margin-left: 0.75rem; |
scroll-m-3.5 | scroll-margin: 0.875rem; |
scroll-mx-3.5 | scroll-margin-left: 0.875rem; scroll-margin-right: 0.875rem; |
scroll-my-3.5 | scroll-margin-top: 0.875rem; scroll-margin-bottom: 0.875rem; |
scroll-mt-3.5 | scroll-margin-top: 0.875rem; |
scroll-mr-3.5 | scroll-margin-right: 0.875rem; |
scroll-mb-3.5 | scroll-margin-bottom: 0.875rem; |
scroll-ml-3.5 | scroll-margin-left: 0.875rem; |
scroll-m-4 | scroll-margin: 1rem; |
scroll-mx-4 | scroll-margin-left: 1rem; scroll-margin-right: 1rem; |
scroll-my-4 | scroll-margin-top: 1rem; scroll-margin-bottom: 1rem; |
scroll-mt-4 | scroll-margin-top: 1rem; |
scroll-mr-4 | scroll-margin-right: 1rem; |
scroll-mb-4 | scroll-margin-bottom: 1rem; |
scroll-ml-4 | scroll-margin-left: 1rem; |
scroll-m-5 | scroll-margin: 1.25rem; |
scroll-mx-5 | scroll-margin-left: 1.25rem; scroll-margin-right: 1.25rem; |
scroll-my-5 | scroll-margin-top: 1.25rem; scroll-margin-bottom: 1.25rem; |
scroll-mt-5 | scroll-margin-top: 1.25rem; |
scroll-mr-5 | scroll-margin-right: 1.25rem; |
scroll-mb-5 | scroll-margin-bottom: 1.25rem; |
scroll-ml-5 | scroll-margin-left: 1.25rem; |
scroll-m-6 | scroll-margin: 1.5rem; |
scroll-mx-6 | scroll-margin-left: 1.5rem; scroll-margin-right: 1.5rem; |
scroll-my-6 | scroll-margin-top: 1.5rem; scroll-margin-bottom: 1.5rem; |
scroll-mt-6 | scroll-margin-top: 1.5rem; |
scroll-mr-6 | scroll-margin-right: 1.5rem; |
scroll-mb-6 | scroll-margin-bottom: 1.5rem; |
scroll-ml-6 | scroll-margin-left: 1.5rem; |
scroll-m-7 | scroll-margin: 1.75rem; |
scroll-mx-7 | scroll-margin-left: 1.75rem; scroll-margin-right: 1.75rem; |
scroll-my-7 | scroll-margin-top: 1.75rem; scroll-margin-bottom: 1.75rem; |
scroll-mt-7 | scroll-margin-top: 1.75rem; |
scroll-mr-7 | scroll-margin-right: 1.75rem; |
scroll-mb-7 | scroll-margin-bottom: 1.75rem; |
scroll-ml-7 | scroll-margin-left: 1.75rem; |
scroll-m-8 | scroll-margin: 2rem; |
scroll-mx-8 | scroll-margin-left: 2rem; scroll-margin-right: 2rem; |
scroll-my-8 | scroll-margin-top: 2rem; scroll-margin-bottom: 2rem; |
scroll-mt-8 | scroll-margin-top: 2rem; |
scroll-mr-8 | scroll-margin-right: 2rem; |
scroll-mb-8 | scroll-margin-bottom: 2rem; |
scroll-ml-8 | scroll-margin-left: 2rem; |
scroll-m-9 | scroll-margin: 2.25rem; |
scroll-mx-9 | scroll-margin-left: 2.25rem; scroll-margin-right: 2.25rem; |
scroll-my-9 | scroll-margin-top: 2.25rem; scroll-margin-bottom: 2.25rem; |
scroll-mt-9 | scroll-margin-top: 2.25rem; |
scroll-mr-9 | scroll-margin-right: 2.25rem; |
scroll-mb-9 | scroll-margin-bottom: 2.25rem; |
scroll-ml-9 | scroll-margin-left: 2.25rem; |
scroll-m-10 | scroll-margin: 2.5rem; |
scroll-mx-10 | scroll-margin-left: 2.5rem; scroll-margin-right: 2.5rem; |
scroll-my-10 | scroll-margin-top: 2.5rem; scroll-margin-bottom: 2.5rem; |
scroll-mt-10 | scroll-margin-top: 2.5rem; |
scroll-mr-10 | scroll-margin-right: 2.5rem; |
scroll-mb-10 | scroll-margin-bottom: 2.5rem; |
scroll-ml-10 | scroll-margin-left: 2.5rem; |
scroll-m-11 | scroll-margin: 2.75rem; |
scroll-mx-11 | scroll-margin-left: 2.75rem; scroll-margin-right: 2.75rem; |
scroll-my-11 | scroll-margin-top: 2.75rem; scroll-margin-bottom: 2.75rem; |
scroll-mt-11 | scroll-margin-top: 2.75rem; |
scroll-mr-11 | scroll-margin-right: 2.75rem; |
scroll-mb-11 | scroll-margin-bottom: 2.75rem; |
scroll-ml-11 | scroll-margin-left: 2.75rem; |
scroll-m-12 | scroll-margin: 3rem; |
scroll-mx-12 | scroll-margin-left: 3rem; scroll-margin-right: 3rem; |
scroll-my-12 | scroll-margin-top: 3rem; scroll-margin-bottom: 3rem; |
scroll-mt-12 | scroll-margin-top: 3rem; |
scroll-mr-12 | scroll-margin-right: 3rem; |
scroll-mb-12 | scroll-margin-bottom: 3rem; |
scroll-ml-12 | scroll-margin-left: 3rem; |
scroll-m-14 | scroll-margin: 3.5rem; |
scroll-mx-14 | scroll-margin-left: 3.5rem; scroll-margin-right: 3.5rem; |
scroll-my-14 | scroll-margin-top: 3.5rem; scroll-margin-bottom: 3.5rem; |
scroll-mt-14 | scroll-margin-top: 3.5rem; |
scroll-mr-14 | scroll-margin-right: 3.5rem; |
scroll-mb-14 | scroll-margin-bottom: 3.5rem; |
scroll-ml-14 | scroll-margin-left: 3.5rem; |
scroll-m-16 | scroll-margin: 4rem; |
scroll-mx-16 | scroll-margin-left: 4rem; scroll-margin-right: 4rem; |
scroll-my-16 | scroll-margin-top: 4rem; scroll-margin-bottom: 4rem; |
scroll-mt-16 | scroll-margin-top: 4rem; |
scroll-mr-16 | scroll-margin-right: 4rem; |
scroll-mb-16 | scroll-margin-bottom: 4rem; |
scroll-ml-16 | scroll-margin-left: 4rem; |
scroll-m-20 | scroll-margin: 5rem; |
scroll-mx-20 | scroll-margin-left: 5rem; scroll-margin-right: 5rem; |
scroll-my-20 | scroll-margin-top: 5rem; scroll-margin-bottom: 5rem; |
scroll-mt-20 | scroll-margin-top: 5rem; |
scroll-mr-20 | scroll-margin-right: 5rem; |
scroll-mb-20 | scroll-margin-bottom: 5rem; |
scroll-ml-20 | scroll-margin-left: 5rem; |
scroll-m-24 | scroll-margin: 6rem; |
scroll-mx-24 | scroll-margin-left: 6rem; scroll-margin-right: 6rem; |
scroll-my-24 | scroll-margin-top: 6rem; scroll-margin-bottom: 6rem; |
scroll-mt-24 | scroll-margin-top: 6rem; |
scroll-mr-24 | scroll-margin-right: 6rem; |
scroll-mb-24 | scroll-margin-bottom: 6rem; |
scroll-ml-24 | scroll-margin-left: 6rem; |
scroll-m-28 | scroll-margin: 7rem; |
scroll-mx-28 | scroll-margin-left: 7rem; scroll-margin-right: 7rem; |
scroll-my-28 | scroll-margin-top: 7rem; scroll-margin-bottom: 7rem; |
scroll-mt-28 | scroll-margin-top: 7rem; |
scroll-mr-28 | scroll-margin-right: 7rem; |
scroll-mb-28 | scroll-margin-bottom: 7rem; |
scroll-ml-28 | scroll-margin-left: 7rem; |
scroll-m-32 | scroll-margin: 8rem; |
scroll-mx-32 | scroll-margin-left: 8rem; scroll-margin-right: 8rem; |
scroll-my-32 | scroll-margin-top: 8rem; scroll-margin-bottom: 8rem; |
scroll-mt-32 | scroll-margin-top: 8rem; |
scroll-mr-32 | scroll-margin-right: 8rem; |
scroll-mb-32 | scroll-margin-bottom: 8rem; |
scroll-ml-32 | scroll-margin-left: 8rem; |
scroll-m-36 | scroll-margin: 9rem; |
scroll-mx-36 | scroll-margin-left: 9rem; scroll-margin-right: 9rem; |
scroll-my-36 | scroll-margin-top: 9rem; scroll-margin-bottom: 9rem; |
scroll-mt-36 | scroll-margin-top: 9rem; |
scroll-mr-36 | scroll-margin-right: 9rem; |
scroll-mb-36 | scroll-margin-bottom: 9rem; |
scroll-ml-36 | scroll-margin-left: 9rem; |
scroll-m-40 | scroll-margin: 10rem; |
scroll-mx-40 | scroll-margin-left: 10rem; scroll-margin-right: 10rem; |
scroll-my-40 | scroll-margin-top: 10rem; scroll-margin-bottom: 10rem; |
scroll-mt-40 | scroll-margin-top: 10rem; |
scroll-mr-40 | scroll-margin-right: 10rem; |
scroll-mb-40 | scroll-margin-bottom: 10rem; |
scroll-ml-40 | scroll-margin-left: 10rem; |
scroll-m-44 | scroll-margin: 11rem; |
scroll-mx-44 | scroll-margin-left: 11rem; scroll-margin-right: 11rem; |
scroll-my-44 | scroll-margin-top: 11rem; scroll-margin-bottom: 11rem; |
scroll-mt-44 | scroll-margin-top: 11rem; |
scroll-mr-44 | scroll-margin-right: 11rem; |
scroll-mb-44 | scroll-margin-bottom: 11rem; |
scroll-ml-44 | scroll-margin-left: 11rem; |
scroll-m-48 | scroll-margin: 12rem; |
scroll-mx-48 | scroll-margin-left: 12rem; scroll-margin-right: 12rem; |
scroll-my-48 | scroll-margin-top: 12rem; scroll-margin-bottom: 12rem; |
scroll-mt-48 | scroll-margin-top: 12rem; |
scroll-mr-48 | scroll-margin-right: 12rem; |
scroll-mb-48 | scroll-margin-bottom: 12rem; |
scroll-ml-48 | scroll-margin-left: 12rem; |
scroll-m-52 | scroll-margin: 13rem; |
scroll-mx-52 | scroll-margin-left: 13rem; scroll-margin-right: 13rem; |
scroll-my-52 | scroll-margin-top: 13rem; scroll-margin-bottom: 13rem; |
scroll-mt-52 | scroll-margin-top: 13rem; |
scroll-mr-52 | scroll-margin-right: 13rem; |
scroll-mb-52 | scroll-margin-bottom: 13rem; |
scroll-ml-52 | scroll-margin-left: 13rem; |
scroll-m-56 | scroll-margin: 14rem; |
scroll-mx-56 | scroll-margin-left: 14rem; scroll-margin-right: 14rem; |
scroll-my-56 | scroll-margin-top: 14rem; scroll-margin-bottom: 14rem; |
scroll-mt-56 | scroll-margin-top: 14rem; |
scroll-mr-56 | scroll-margin-right: 14rem; |
scroll-mb-56 | scroll-margin-bottom: 14rem; |
scroll-ml-56 | scroll-margin-left: 14rem; |
scroll-m-60 | scroll-margin: 15rem; |
scroll-mx-60 | scroll-margin-left: 15rem; scroll-margin-right: 15rem; |
scroll-my-60 | scroll-margin-top: 15rem; scroll-margin-bottom: 15rem; |
scroll-mt-60 | scroll-margin-top: 15rem; |
scroll-mr-60 | scroll-margin-right: 15rem; |
scroll-mb-60 | scroll-margin-bottom: 15rem; |
scroll-ml-60 | scroll-margin-left: 15rem; |
scroll-m-64 | scroll-margin: 16rem; |
scroll-mx-64 | scroll-margin-left: 16rem; scroll-margin-right: 16rem; |
scroll-my-64 | scroll-margin-top: 16rem; scroll-margin-bottom: 16rem; |
scroll-mt-64 | scroll-margin-top: 16rem; |
scroll-mr-64 | scroll-margin-right: 16rem; |
scroll-mb-64 | scroll-margin-bottom: 16rem; |
scroll-ml-64 | scroll-margin-left: 16rem; |
scroll-m-72 | scroll-margin: 18rem; |
scroll-mx-72 | scroll-margin-left: 18rem; scroll-margin-right: 18rem; |
scroll-my-72 | scroll-margin-top: 18rem; scroll-margin-bottom: 18rem; |
scroll-mt-72 | scroll-margin-top: 18rem; |
scroll-mr-72 | scroll-margin-right: 18rem; |
scroll-mb-72 | scroll-margin-bottom: 18rem; |
scroll-ml-72 | scroll-margin-left: 18rem; |
scroll-m-80 | scroll-margin: 20rem; |
scroll-mx-80 | scroll-margin-left: 20rem; scroll-margin-right: 20rem; |
scroll-my-80 | scroll-margin-top: 20rem; scroll-margin-bottom: 20rem; |
scroll-mt-80 | scroll-margin-top: 20rem; |
scroll-mr-80 | scroll-margin-right: 20rem; |
scroll-mb-80 | scroll-margin-bottom: 20rem; |
scroll-ml-80 | scroll-margin-left: 20rem; |
scroll-m-96 | scroll-margin: 24rem; |
scroll-mx-96 | scroll-margin-left: 24rem; scroll-margin-right: 24rem; |
scroll-my-96 | scroll-margin-top: 24rem; scroll-margin-bottom: 24rem; |
scroll-mt-96 | scroll-margin-top: 24rem; |
scroll-mr-96 | scroll-margin-right: 24rem; |
scroll-mb-96 | scroll-margin-bottom: 24rem; |
scroll-ml-96 | scroll-margin-left: 24rem; |
Show all classes
Basic usage
Setting the scroll margin
Use the scroll-m{side}-{size}
utilities to set the scroll offset around items within a snap container.
Scroll in the grid of images to see the expected behaviour
<div class="snap-x ...">
<div class="scroll-ml-6 snap-start ...">
<img src="https://images.unsplash.com/photo-1604999565976-8913ad2ddb7c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=320&h=160&q=80" />
</div>
<div class="scroll-ml-6 snap-start ...">
<img src="https://images.unsplash.com/photo-1540206351-d6465b3ac5c1?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=320&h=160&q=80" />
</div>
<div class="scroll-ml-6 snap-start ...">
<img src="https://images.unsplash.com/photo-1622890806166-111d7f6c7c97?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=320&h=160&q=80" />
</div>
<div class="scroll-ml-6 snap-start ...">
<img src="https://images.unsplash.com/photo-1590523277543-a94d2e4eb00b?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=320&h=160&q=80" />
</div>
<div class="scroll-ml-6 snap-start ...">
<img src="https://images.unsplash.com/photo-1575424909138-46b05e5919ec?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=320&h=160&q=80" />
</div>
</div>
Using negative values
To use a negative scroll margin value, prefix the class name with a dash to convert it to a negative value.
<div class="-scroll-ml-6 snap-start ...">
<!-- ... -->
</div>
Applying conditionally
Hover, focus, and other states
Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:scroll-m-0
to only apply the scroll-m-0
utility on hover.
<div class="scroll-m-8 hover:scroll-m-0">
<!-- ... -->
</div>
For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.
Breakpoints and media queries
You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:scroll-m-0
to apply the scroll-m-0
utility at only medium screen sizes and above.
<div class="scroll-m-8 md:scroll-m-0">
<!-- ... -->
</div>
To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.
Using custom values
Customizing your theme
By default, Tailwind’s scroll margin scale uses the default spacing scale. You can customize your spacing scale by editing theme.spacing
or theme.extend.spacing
in your tailwind.config.js
file.
tailwind.config.js
module.exports = { theme: { extend: { spacing: { '96': '24rem', } } }}
Alternatively, you can customize just the scroll margin scale by editing theme.scrollMargin
or theme.extend.scrollMargin
in your tailwind.config.js
file.
tailwind.config.js
module.exports = { theme: { extend: { scrollMargin: { '96': '24rem', }, } }}
Learn more about customizing the default theme in the theme customization documentation.
Arbitrary values
If you need to use a one-off scroll-margin
value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.
<div class="scroll-m-[24rem]">
<!-- ... -->
</div>
Learn more about arbitrary value support in the arbitrary values documentation.