Interactivity

Scroll Padding

Utilities for controlling an element’s scroll offset within a snap container.

Quick reference

Class
Properties
scroll-p-0scroll-padding: 0px;
scroll-px-0scroll-padding-left: 0px; scroll-padding-right: 0px;
scroll-py-0scroll-padding-top: 0px; scroll-padding-bottom: 0px;
scroll-pt-0scroll-padding-top: 0px;
scroll-pr-0scroll-padding-right: 0px;
scroll-pb-0scroll-padding-bottom: 0px;
scroll-pl-0scroll-padding-left: 0px;
scroll-p-pxscroll-padding: 1px;
scroll-px-pxscroll-padding-left: 1px; scroll-padding-right: 1px;
scroll-py-pxscroll-padding-top: 1px; scroll-padding-bottom: 1px;
scroll-pt-pxscroll-padding-top: 1px;
scroll-pr-pxscroll-padding-right: 1px;
scroll-pb-pxscroll-padding-bottom: 1px;
scroll-pl-pxscroll-padding-left: 1px;
scroll-p-0.5scroll-padding: 0.125rem;
scroll-px-0.5scroll-padding-left: 0.125rem; scroll-padding-right: 0.125rem;
scroll-py-0.5scroll-padding-top: 0.125rem; scroll-padding-bottom: 0.125rem;
scroll-pt-0.5scroll-padding-top: 0.125rem;
scroll-pr-0.5scroll-padding-right: 0.125rem;
scroll-pb-0.5scroll-padding-bottom: 0.125rem;
scroll-pl-0.5scroll-padding-left: 0.125rem;
scroll-p-1scroll-padding: 0.25rem;
scroll-px-1scroll-padding-left: 0.25rem; scroll-padding-right: 0.25rem;
scroll-py-1scroll-padding-top: 0.25rem; scroll-padding-bottom: 0.25rem;
scroll-pt-1scroll-padding-top: 0.25rem;
scroll-pr-1scroll-padding-right: 0.25rem;
scroll-pb-1scroll-padding-bottom: 0.25rem;
scroll-pl-1scroll-padding-left: 0.25rem;
scroll-p-1.5scroll-padding: 0.375rem;
scroll-px-1.5scroll-padding-left: 0.375rem; scroll-padding-right: 0.375rem;
scroll-py-1.5scroll-padding-top: 0.375rem; scroll-padding-bottom: 0.375rem;
scroll-pt-1.5scroll-padding-top: 0.375rem;
scroll-pr-1.5scroll-padding-right: 0.375rem;
scroll-pb-1.5scroll-padding-bottom: 0.375rem;
scroll-pl-1.5scroll-padding-left: 0.375rem;
scroll-p-2scroll-padding: 0.5rem;
scroll-px-2scroll-padding-left: 0.5rem; scroll-padding-right: 0.5rem;
scroll-py-2scroll-padding-top: 0.5rem; scroll-padding-bottom: 0.5rem;
scroll-pt-2scroll-padding-top: 0.5rem;
scroll-pr-2scroll-padding-right: 0.5rem;
scroll-pb-2scroll-padding-bottom: 0.5rem;
scroll-pl-2scroll-padding-left: 0.5rem;
scroll-p-2.5scroll-padding: 0.625rem;
scroll-px-2.5scroll-padding-left: 0.625rem; scroll-padding-right: 0.625rem;
scroll-py-2.5scroll-padding-top: 0.625rem; scroll-padding-bottom: 0.625rem;
scroll-pt-2.5scroll-padding-top: 0.625rem;
scroll-pr-2.5scroll-padding-right: 0.625rem;
scroll-pb-2.5scroll-padding-bottom: 0.625rem;
scroll-pl-2.5scroll-padding-left: 0.625rem;
scroll-p-3scroll-padding: 0.75rem;
scroll-px-3scroll-padding-left: 0.75rem; scroll-padding-right: 0.75rem;
scroll-py-3scroll-padding-top: 0.75rem; scroll-padding-bottom: 0.75rem;
scroll-pt-3scroll-padding-top: 0.75rem;
scroll-pr-3scroll-padding-right: 0.75rem;
scroll-pb-3scroll-padding-bottom: 0.75rem;
scroll-pl-3scroll-padding-left: 0.75rem;
scroll-p-3.5scroll-padding: 0.875rem;
scroll-px-3.5scroll-padding-left: 0.875rem; scroll-padding-right: 0.875rem;
scroll-py-3.5scroll-padding-top: 0.875rem; scroll-padding-bottom: 0.875rem;
scroll-pt-3.5scroll-padding-top: 0.875rem;
scroll-pr-3.5scroll-padding-right: 0.875rem;
scroll-pb-3.5scroll-padding-bottom: 0.875rem;
scroll-pl-3.5scroll-padding-left: 0.875rem;
scroll-p-4scroll-padding: 1rem;
scroll-px-4scroll-padding-left: 1rem; scroll-padding-right: 1rem;
scroll-py-4scroll-padding-top: 1rem; scroll-padding-bottom: 1rem;
scroll-pt-4scroll-padding-top: 1rem;
scroll-pr-4scroll-padding-right: 1rem;
scroll-pb-4scroll-padding-bottom: 1rem;
scroll-pl-4scroll-padding-left: 1rem;
scroll-p-5scroll-padding: 1.25rem;
scroll-px-5scroll-padding-left: 1.25rem; scroll-padding-right: 1.25rem;
scroll-py-5scroll-padding-top: 1.25rem; scroll-padding-bottom: 1.25rem;
scroll-pt-5scroll-padding-top: 1.25rem;
scroll-pr-5scroll-padding-right: 1.25rem;
scroll-pb-5scroll-padding-bottom: 1.25rem;
scroll-pl-5scroll-padding-left: 1.25rem;
scroll-p-6scroll-padding: 1.5rem;
scroll-px-6scroll-padding-left: 1.5rem; scroll-padding-right: 1.5rem;
scroll-py-6scroll-padding-top: 1.5rem; scroll-padding-bottom: 1.5rem;
scroll-pt-6scroll-padding-top: 1.5rem;
scroll-pr-6scroll-padding-right: 1.5rem;
scroll-pb-6scroll-padding-bottom: 1.5rem;
scroll-pl-6scroll-padding-left: 1.5rem;
scroll-p-7scroll-padding: 1.75rem;
scroll-px-7scroll-padding-left: 1.75rem; scroll-padding-right: 1.75rem;
scroll-py-7scroll-padding-top: 1.75rem; scroll-padding-bottom: 1.75rem;
scroll-pt-7scroll-padding-top: 1.75rem;
scroll-pr-7scroll-padding-right: 1.75rem;
scroll-pb-7scroll-padding-bottom: 1.75rem;
scroll-pl-7scroll-padding-left: 1.75rem;
scroll-p-8scroll-padding: 2rem;
scroll-px-8scroll-padding-left: 2rem; scroll-padding-right: 2rem;
scroll-py-8scroll-padding-top: 2rem; scroll-padding-bottom: 2rem;
scroll-pt-8scroll-padding-top: 2rem;
scroll-pr-8scroll-padding-right: 2rem;
scroll-pb-8scroll-padding-bottom: 2rem;
scroll-pl-8scroll-padding-left: 2rem;
scroll-p-9scroll-padding: 2.25rem;
scroll-px-9scroll-padding-left: 2.25rem; scroll-padding-right: 2.25rem;
scroll-py-9scroll-padding-top: 2.25rem; scroll-padding-bottom: 2.25rem;
scroll-pt-9scroll-padding-top: 2.25rem;
scroll-pr-9scroll-padding-right: 2.25rem;
scroll-pb-9scroll-padding-bottom: 2.25rem;
scroll-pl-9scroll-padding-left: 2.25rem;
scroll-p-10scroll-padding: 2.5rem;
scroll-px-10scroll-padding-left: 2.5rem; scroll-padding-right: 2.5rem;
scroll-py-10scroll-padding-top: 2.5rem; scroll-padding-bottom: 2.5rem;
scroll-pt-10scroll-padding-top: 2.5rem;
scroll-pr-10scroll-padding-right: 2.5rem;
scroll-pb-10scroll-padding-bottom: 2.5rem;
scroll-pl-10scroll-padding-left: 2.5rem;
scroll-p-11scroll-padding: 2.75rem;
scroll-px-11scroll-padding-left: 2.75rem; scroll-padding-right: 2.75rem;
scroll-py-11scroll-padding-top: 2.75rem; scroll-padding-bottom: 2.75rem;
scroll-pt-11scroll-padding-top: 2.75rem;
scroll-pr-11scroll-padding-right: 2.75rem;
scroll-pb-11scroll-padding-bottom: 2.75rem;
scroll-pl-11scroll-padding-left: 2.75rem;
scroll-p-12scroll-padding: 3rem;
scroll-px-12scroll-padding-left: 3rem; scroll-padding-right: 3rem;
scroll-py-12scroll-padding-top: 3rem; scroll-padding-bottom: 3rem;
scroll-pt-12scroll-padding-top: 3rem;
scroll-pr-12scroll-padding-right: 3rem;
scroll-pb-12scroll-padding-bottom: 3rem;
scroll-pl-12scroll-padding-left: 3rem;
scroll-p-14scroll-padding: 3.5rem;
scroll-px-14scroll-padding-left: 3.5rem; scroll-padding-right: 3.5rem;
scroll-py-14scroll-padding-top: 3.5rem; scroll-padding-bottom: 3.5rem;
scroll-pt-14scroll-padding-top: 3.5rem;
scroll-pr-14scroll-padding-right: 3.5rem;
scroll-pb-14scroll-padding-bottom: 3.5rem;
scroll-pl-14scroll-padding-left: 3.5rem;
scroll-p-16scroll-padding: 4rem;
scroll-px-16scroll-padding-left: 4rem; scroll-padding-right: 4rem;
scroll-py-16scroll-padding-top: 4rem; scroll-padding-bottom: 4rem;
scroll-pt-16scroll-padding-top: 4rem;
scroll-pr-16scroll-padding-right: 4rem;
scroll-pb-16scroll-padding-bottom: 4rem;
scroll-pl-16scroll-padding-left: 4rem;
scroll-p-20scroll-padding: 5rem;
scroll-px-20scroll-padding-left: 5rem; scroll-padding-right: 5rem;
scroll-py-20scroll-padding-top: 5rem; scroll-padding-bottom: 5rem;
scroll-pt-20scroll-padding-top: 5rem;
scroll-pr-20scroll-padding-right: 5rem;
scroll-pb-20scroll-padding-bottom: 5rem;
scroll-pl-20scroll-padding-left: 5rem;
scroll-p-24scroll-padding: 6rem;
scroll-px-24scroll-padding-left: 6rem; scroll-padding-right: 6rem;
scroll-py-24scroll-padding-top: 6rem; scroll-padding-bottom: 6rem;
scroll-pt-24scroll-padding-top: 6rem;
scroll-pr-24scroll-padding-right: 6rem;
scroll-pb-24scroll-padding-bottom: 6rem;
scroll-pl-24scroll-padding-left: 6rem;
scroll-p-28scroll-padding: 7rem;
scroll-px-28scroll-padding-left: 7rem; scroll-padding-right: 7rem;
scroll-py-28scroll-padding-top: 7rem; scroll-padding-bottom: 7rem;
scroll-pt-28scroll-padding-top: 7rem;
scroll-pr-28scroll-padding-right: 7rem;
scroll-pb-28scroll-padding-bottom: 7rem;
scroll-pl-28scroll-padding-left: 7rem;
scroll-p-32scroll-padding: 8rem;
scroll-px-32scroll-padding-left: 8rem; scroll-padding-right: 8rem;
scroll-py-32scroll-padding-top: 8rem; scroll-padding-bottom: 8rem;
scroll-pt-32scroll-padding-top: 8rem;
scroll-pr-32scroll-padding-right: 8rem;
scroll-pb-32scroll-padding-bottom: 8rem;
scroll-pl-32scroll-padding-left: 8rem;
scroll-p-36scroll-padding: 9rem;
scroll-px-36scroll-padding-left: 9rem; scroll-padding-right: 9rem;
scroll-py-36scroll-padding-top: 9rem; scroll-padding-bottom: 9rem;
scroll-pt-36scroll-padding-top: 9rem;
scroll-pr-36scroll-padding-right: 9rem;
scroll-pb-36scroll-padding-bottom: 9rem;
scroll-pl-36scroll-padding-left: 9rem;
scroll-p-40scroll-padding: 10rem;
scroll-px-40scroll-padding-left: 10rem; scroll-padding-right: 10rem;
scroll-py-40scroll-padding-top: 10rem; scroll-padding-bottom: 10rem;
scroll-pt-40scroll-padding-top: 10rem;
scroll-pr-40scroll-padding-right: 10rem;
scroll-pb-40scroll-padding-bottom: 10rem;
scroll-pl-40scroll-padding-left: 10rem;
scroll-p-44scroll-padding: 11rem;
scroll-px-44scroll-padding-left: 11rem; scroll-padding-right: 11rem;
scroll-py-44scroll-padding-top: 11rem; scroll-padding-bottom: 11rem;
scroll-pt-44scroll-padding-top: 11rem;
scroll-pr-44scroll-padding-right: 11rem;
scroll-pb-44scroll-padding-bottom: 11rem;
scroll-pl-44scroll-padding-left: 11rem;
scroll-p-48scroll-padding: 12rem;
scroll-px-48scroll-padding-left: 12rem; scroll-padding-right: 12rem;
scroll-py-48scroll-padding-top: 12rem; scroll-padding-bottom: 12rem;
scroll-pt-48scroll-padding-top: 12rem;
scroll-pr-48scroll-padding-right: 12rem;
scroll-pb-48scroll-padding-bottom: 12rem;
scroll-pl-48scroll-padding-left: 12rem;
scroll-p-52scroll-padding: 13rem;
scroll-px-52scroll-padding-left: 13rem; scroll-padding-right: 13rem;
scroll-py-52scroll-padding-top: 13rem; scroll-padding-bottom: 13rem;
scroll-pt-52scroll-padding-top: 13rem;
scroll-pr-52scroll-padding-right: 13rem;
scroll-pb-52scroll-padding-bottom: 13rem;
scroll-pl-52scroll-padding-left: 13rem;
scroll-p-56scroll-padding: 14rem;
scroll-px-56scroll-padding-left: 14rem; scroll-padding-right: 14rem;
scroll-py-56scroll-padding-top: 14rem; scroll-padding-bottom: 14rem;
scroll-pt-56scroll-padding-top: 14rem;
scroll-pr-56scroll-padding-right: 14rem;
scroll-pb-56scroll-padding-bottom: 14rem;
scroll-pl-56scroll-padding-left: 14rem;
scroll-p-60scroll-padding: 15rem;
scroll-px-60scroll-padding-left: 15rem; scroll-padding-right: 15rem;
scroll-py-60scroll-padding-top: 15rem; scroll-padding-bottom: 15rem;
scroll-pt-60scroll-padding-top: 15rem;
scroll-pr-60scroll-padding-right: 15rem;
scroll-pb-60scroll-padding-bottom: 15rem;
scroll-pl-60scroll-padding-left: 15rem;
scroll-p-64scroll-padding: 16rem;
scroll-px-64scroll-padding-left: 16rem; scroll-padding-right: 16rem;
scroll-py-64scroll-padding-top: 16rem; scroll-padding-bottom: 16rem;
scroll-pt-64scroll-padding-top: 16rem;
scroll-pr-64scroll-padding-right: 16rem;
scroll-pb-64scroll-padding-bottom: 16rem;
scroll-pl-64scroll-padding-left: 16rem;
scroll-p-72scroll-padding: 18rem;
scroll-px-72scroll-padding-left: 18rem; scroll-padding-right: 18rem;
scroll-py-72scroll-padding-top: 18rem; scroll-padding-bottom: 18rem;
scroll-pt-72scroll-padding-top: 18rem;
scroll-pr-72scroll-padding-right: 18rem;
scroll-pb-72scroll-padding-bottom: 18rem;
scroll-pl-72scroll-padding-left: 18rem;
scroll-p-80scroll-padding: 20rem;
scroll-px-80scroll-padding-left: 20rem; scroll-padding-right: 20rem;
scroll-py-80scroll-padding-top: 20rem; scroll-padding-bottom: 20rem;
scroll-pt-80scroll-padding-top: 20rem;
scroll-pr-80scroll-padding-right: 20rem;
scroll-pb-80scroll-padding-bottom: 20rem;
scroll-pl-80scroll-padding-left: 20rem;
scroll-p-96scroll-padding: 24rem;
scroll-px-96scroll-padding-left: 24rem; scroll-padding-right: 24rem;
scroll-py-96scroll-padding-top: 24rem; scroll-padding-bottom: 24rem;
scroll-pt-96scroll-padding-top: 24rem;
scroll-pr-96scroll-padding-right: 24rem;
scroll-pb-96scroll-padding-bottom: 24rem;
scroll-pl-96scroll-padding-left: 24rem;

Show all classes

Basic usage

Setting the scroll padding

Use the scroll-p{side}-{size} utilities to set the scroll offset of an element within a snap container.

Scroll Padding - 图1

Scroll in the grid of images to see the expected behaviour

Scroll Padding - 图2

  1. <div class="scroll-pl-6 snap-x ...">
  2. <div class="snap-start ...">
  3. <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" />
  4. </div>
  5. <div class="snap-start ...">
  6. <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" />
  7. </div>
  8. <div class="snap-start ...">
  9. <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" />
  10. </div>
  11. <div class="snap-start ...">
  12. <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" />
  13. </div>
  14. <div class="snap-start ...">
  15. <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" />
  16. </div>
  17. </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-p-0 to only apply the scroll-p-0 utility on hover.

  1. <div class="scroll-p-8 hover:scroll-p-0">
  2. <!-- ... -->
  3. </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-p-0 to apply the scroll-p-0 utility at only medium screen sizes and above.

  1. <div class="scroll-p-8 md:scroll-p-0">
  2. <!-- ... -->
  3. </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 padding 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

  1. module.exports = { theme: { extend: { spacing: { '96': '24rem', } } }}

Alternatively, you can customize just the scroll padding scale by editing theme.scrollPadding or theme.extend.scrollPadding in your tailwind.config.js file.

tailwind.config.js

  1. module.exports = { theme: { extend: { scrollPadding: { '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-padding 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.

  1. <div class="scroll-p-[24rem]">
  2. <!-- ... -->
  3. </div>

Learn more about arbitrary value support in the arbitrary values documentation.