Scroll Margin
Utilities for controlling the scroll offset around items in a snap container.
Show all classes
Use the utilities to set the scroll offset around items within a snap container.
Scroll in the grid of images to see the expected behaviour
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>
Scroll in the grid of images to see the expected behaviour
For more control, you can also use the to conditionally apply specific styles depending on the current text direction.
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.
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.
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: {
spacing: {
}
}
}
}
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
Learn more about customizing the default theme in the documentation.
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]">
<!-- ... -->
Learn more about arbitrary value support in the documentation.