Tailwind CSS Scroll Padding
Scroll padding is used to adjust the starting position of scroll snaps when navigating through a scrollable container. Tailwind CSS provides a suite of utility classes dedicated to implementing scrolling padding properties.
These utilities enable you to efficiently manage scroll snapping behavior without manually writing custom CSS, making them ideal for modern responsive layouts.
Class | Properties | Example |
---|---|---|
scroll-p-0 | scroll-padding: 0px; | <div className="scroll-p-0"></div> |
scroll-px-0 | scroll-padding-left: 0px;
scroll-padding-right: 0px; | <div className="scroll-px-0"></div> |
scroll-py-0 | scroll-padding-top: 0px;
scroll-padding-bottom: 0px; | <div className="scroll-py-0"></div> |
scroll-ps-0 | scroll-padding-inline-start: 0px; | <div className="scroll-ps-0"></div> |
scroll-pe-0 | scroll-padding-inline-end: 0px; | <div className="scroll-pe-0"></div> |
scroll-pt-0 | scroll-padding-top: 0px; | <div className="scroll-pt-0"></div> |
scroll-pr-0 | scroll-padding-right: 0px; | <div className="scroll-pr-0"></div> |
scroll-pb-0 | scroll-padding-bottom: 0px; | <div className="scroll-pb-0"></div> |
scroll-pl-0 | scroll-padding-left: 0px; | <div className="scroll-pl-0"></div> |
scroll-p-px | scroll-padding: 1px; | <div className="scroll-p-px"></div> |
scroll-px-px | scroll-padding-left: 1px;
scroll-padding-right: 1px; | <div className="scroll-px-px"></div> |
scroll-py-px | scroll-padding-top: 1px;
scroll-padding-bottom: 1px; | <div className="scroll-py-px"></div> |
scroll-ps-px | scroll-padding-inline-start: 1px; | <div className="scroll-ps-px"></div> |
scroll-pe-px | scroll-padding-inline-end: 1px; | <div className="scroll-pe-px"></div> |
scroll-pt-px | scroll-padding-top: 1px; | <div className="scroll-pt-px"></div> |
scroll-pr-px | scroll-padding-right: 1px; | <div className="scroll-pr-px"></div> |
scroll-pb-px | scroll-padding-bottom: 1px; | <div className="scroll-pb-px"></div> |
scroll-pl-px | scroll-padding-left: 1px; | <div className="scroll-pl-px"></div> |
scroll-p-0.5 | scroll-padding: 0.125rem; | <div className="scroll-p-0.5"></div> |
scroll-px-0.5 | scroll-padding-left: 0.125rem;
scroll-padding-right: 0.125rem; | <div className="scroll-px-0.5"></div> |
scroll-py-0.5 | scroll-padding-top: 0.125rem;
scroll-padding-bottom: 0.125rem; | <div className="scroll-py-0.5"></div> |
scroll-ps-0.5 | scroll-padding-inline-start: 0.125rem; | <div className="scroll-ps-0.5"></div> |
scroll-pe-0.5 | scroll-padding-inline-end: 0.125rem; | <div className="scroll-pe-0.5"></div> |
scroll-pt-0.5 | scroll-padding-top: 0.125rem; | <div className="scroll-pt-0.5"></div> |
scroll-pr-0.5 | scroll-padding-right: 0.125rem; | <div className="scroll-pr-0.5"></div> |
scroll-pb-0.5 | scroll-padding-bottom: 0.125rem; | <div className="scroll-pb-0.5"></div> |
scroll-pl-0.5 | scroll-padding-left: 0.125rem; | <div className="scroll-pl-0.5"></div> |
scroll-p-1 | scroll-padding: 0.25rem; | <div className="scroll-p-1"></div> |
scroll-px-1 | scroll-padding-left: 0.25rem;
scroll-padding-right: 0.25rem; | <div className="scroll-px-1"></div> |
scroll-py-1 | scroll-padding-top: 0.25rem;
scroll-padding-bottom: 0.25rem; | <div className="scroll-py-1"></div> |
scroll-ps-1 | scroll-padding-inline-start: 0.25rem; | <div className="scroll-ps-1"></div> |
scroll-pe-1 | scroll-padding-inline-end: 0.25rem; | <div className="scroll-pe-1"></div> |
scroll-pt-1 | scroll-padding-top: 0.25rem; | <div className="scroll-pt-1"></div> |
scroll-pr-1 | scroll-padding-right: 0.25rem; | <div className="scroll-pr-1"></div> |
scroll-pb-1 | scroll-padding-bottom: 0.25rem; | <div className="scroll-pb-1"></div> |
scroll-pl-1 | scroll-padding-left: 0.25rem; | <div className="scroll-pl-1"></div> |
scroll-p-1.5 | scroll-padding: 0.375rem; | <div className="scroll-p-1.5"></div> |
scroll-px-1.5 | scroll-padding-left: 0.375rem;
scroll-padding-right: 0.375rem; | <div className="scroll-px-1.5"></div> |
scroll-py-1.5 | scroll-padding-top: 0.375rem;
scroll-padding-bottom: 0.375rem; | <div className="scroll-py-1.5"></div> |
scroll-ps-1.5 | scroll-padding-inline-start: 0.375rem; | <div className="scroll-ps-1.5"></div> |
scroll-pe-1.5 | scroll-padding-inline-end: 0.375rem; | <div className="scroll-pe-1.5"></div> |
scroll-pt-1.5 | scroll-padding-top: 0.375rem; | <div className="scroll-pt-1.5"></div> |
scroll-pr-1.5 | scroll-padding-right: 0.375rem; | <div className="scroll-pr-1.5"></div> |
scroll-pb-1.5 | scroll-padding-bottom: 0.375rem; | <div className="scroll-pb-1.5"></div> |
scroll-pl-1.5 | scroll-padding-left: 0.375rem; | <div className="scroll-pl-1.5"></div> |
scroll-p-2 | scroll-padding: 0.5rem; | <div className="scroll-p-2"></div> |
scroll-px-2 | scroll-padding-left: 0.5rem;
scroll-padding-right: 0.5rem; | <div className="scroll-px-2"></div> |
scroll-py-2 | scroll-padding-top: 0.5rem;
scroll-padding-bottom: 0.5rem; | <div className="scroll-py-2"></div> |
scroll-ps-2 | scroll-padding-inline-start: 0.5rem; | <div className="scroll-ps-2"></div> |
scroll-pe-2 | scroll-padding-inline-end: 0.5rem; | <div className="scroll-pe-2"></div> |
scroll-pt-2 | scroll-padding-top: 0.5rem; | <div className="scroll-pt-2"></div> |
scroll-pr-2 | scroll-padding-right: 0.5rem; | <div className="scroll-pr-2"></div> |
scroll-pb-2 | scroll-padding-bottom: 0.5rem; | <div className="scroll-pb-2"></div> |
scroll-pl-2 | scroll-padding-left: 0.5rem; | <div className="scroll-pl-2"></div> |
scroll-p-2.5 | scroll-padding: 0.625rem; | <div className="scroll-p-2.5"></div> |
scroll-px-2.5 | scroll-padding-left: 0.625rem;
scroll-padding-right: 0.625rem; | <div className="scroll-px-2.5"></div> |
scroll-py-2.5 | scroll-padding-top: 0.625rem;
scroll-padding-bottom: 0.625rem; | <div className="scroll-py-2.5"></div> |
scroll-ps-2.5 | scroll-padding-inline-start: 0.625rem; | <div className="scroll-ps-2.5"></div> |
scroll-pe-2.5 | scroll-padding-inline-end: 0.625rem; | <div className="scroll-pe-2.5"></div> |
scroll-pt-2.5 | scroll-padding-top: 0.625rem; | <div className="scroll-pt-2.5"></div> |
scroll-pr-2.5 | scroll-padding-right: 0.625rem; | <div className="scroll-pr-2.5"></div> |
scroll-pb-2.5 | scroll-padding-bottom: 0.625rem; | <div className="scroll-pb-2.5"></div> |
scroll-pl-2.5 | scroll-padding-left: 0.625rem; | <div className="scroll-pl-2.5"></div> |
scroll-p-3 | scroll-padding: 0.75rem; | <div className="scroll-p-3"></div> |
scroll-px-3 | scroll-padding-left: 0.75rem;
scroll-padding-right: 0.75rem; | <div className="scroll-px-3"></div> |
scroll-py-3 | scroll-padding-top: 0.75rem;
scroll-padding-bottom: 0.75rem; | <div className="scroll-py-3"></div> |
scroll-ps-3 | scroll-padding-inline-start: 0.75rem; | <div className="scroll-ps-3"></div> |
scroll-pe-3 | scroll-padding-inline-end: 0.75rem; | <div className="scroll-pe-3"></div> |
scroll-pt-3 | scroll-padding-top: 0.75rem; | <div className="scroll-pt-3"></div> |
scroll-pr-3 | scroll-padding-right: 0.75rem; | <div className="scroll-pr-3"></div> |
scroll-pb-3 | scroll-padding-bottom: 0.75rem; | <div className="scroll-pb-3"></div> |
scroll-pl-3 | scroll-padding-left: 0.75rem; | <div className="scroll-pl-3"></div> |
scroll-p-3.5 | scroll-padding: 0.875rem; | <div className="scroll-p-3.5"></div> |
scroll-px-3.5 | scroll-padding-left: 0.875rem;
scroll-padding-right: 0.875rem; | <div className="scroll-px-3.5"></div> |
scroll-py-3.5 | scroll-padding-top: 0.875rem;
scroll-padding-bottom: 0.875rem; | <div className="scroll-py-3.5"></div> |
scroll-ps-3.5 | scroll-padding-inline-start: 0.875rem; | <div className="scroll-ps-3.5"></div> |
scroll-pe-3.5 | scroll-padding-inline-end: 0.875rem; | <div className="scroll-pe-3.5"></div> |
scroll-pt-3.5 | scroll-padding-top: 0.875rem; | <div className="scroll-pt-3.5"></div> |
scroll-pr-3.5 | scroll-padding-right: 0.875rem; | <div className="scroll-pr-3.5"></div> |
scroll-pb-3.5 | scroll-padding-bottom: 0.875rem; | <div className="scroll-pb-3.5"></div> |
scroll-pl-3.5 | scroll-padding-left: 0.875rem; | <div className="scroll-pl-3.5"></div> |
scroll-p-4 | scroll-padding: 1rem; | <div className="scroll-p-4"></div> |
scroll-px-4 | scroll-padding-left: 1rem;
scroll-padding-right: 1rem; | <div className="scroll-px-4"></div> |
scroll-py-4 | scroll-padding-top: 1rem;
scroll-padding-bottom: 1rem; | <div className="scroll-py-4"></div> |
scroll-ps-4 | scroll-padding-inline-start: 1rem; | <div className="scroll-ps-4"></div> |
scroll-pe-4 | scroll-padding-inline-end: 1rem; | <div className="scroll-pe-4"></div> |
scroll-pt-4 | scroll-padding-top: 1rem; | <div className="scroll-pt-4"></div> |
scroll-pr-4 | scroll-padding-right: 1rem; | <div className="scroll-pr-4"></div> |
scroll-pb-4 | scroll-padding-bottom: 1rem; | <div className="scroll-pb-4"></div> |
scroll-pl-4 | scroll-padding-left: 1rem; | <div className="scroll-pl-4"></div> |
scroll-p-5 | scroll-padding: 1.25rem; | <div className="scroll-p-5"></div> |
scroll-px-5 | scroll-padding-left: 1.25rem;
scroll-padding-right: 1.25rem; | <div className="scroll-px-5"></div> |
scroll-py-5 | scroll-padding-top: 1.25rem;
scroll-padding-bottom: 1.25rem; | <div className="scroll-py-5"></div> |
scroll-ps-5 | scroll-padding-inline-start: 1.25rem; | <div className="scroll-ps-5"></div> |
scroll-pe-5 | scroll-padding-inline-end: 1.25rem; | <div className="scroll-pe-5"></div> |
scroll-pt-5 | scroll-padding-top: 1.25rem; | <div className="scroll-pt-5"></div> |
scroll-pr-5 | scroll-padding-right: 1.25rem; | <div className="scroll-pr-5"></div> |
scroll-pb-5 | scroll-padding-bottom: 1.25rem; | <div className="scroll-pb-5"></div> |
scroll-pl-5 | scroll-padding-left: 1.25rem; | <div className="scroll-pl-5"></div> |
scroll-p-6 | scroll-padding: 1.5rem; | <div className="scroll-p-6"></div> |
scroll-px-6 | scroll-padding-left: 1.5rem;
scroll-padding-right: 1.5rem; | <div className="scroll-px-6"></div> |
scroll-py-6 | scroll-padding-top: 1.5rem;
scroll-padding-bottom: 1.5rem; | <div className="scroll-py-6"></div> |
scroll-ps-6 | scroll-padding-inline-start: 1.5rem; | <div className="scroll-ps-6"></div> |
scroll-pe-6 | scroll-padding-inline-end: 1.5rem; | <div className="scroll-pe-6"></div> |
scroll-pt-6 | scroll-padding-top: 1.5rem; | <div className="scroll-pt-6"></div> |
scroll-pr-6 | scroll-padding-right: 1.5rem; | <div className="scroll-pr-6"></div> |
scroll-pb-6 | scroll-padding-bottom: 1.5rem; | <div className="scroll-pb-6"></div> |
scroll-pl-6 | scroll-padding-left: 1.5rem; | <div className="scroll-pl-6"></div> |
scroll-p-7 | scroll-padding: 1.75rem; | <div className="scroll-p-7"></div> |
scroll-px-7 | scroll-padding-left: 1.75rem;
scroll-padding-right: 1.75rem; | <div className="scroll-px-7"></div> |
scroll-py-7 | scroll-padding-top: 1.75rem;
scroll-padding-bottom: 1.75rem; | <div className="scroll-py-7"></div> |
scroll-ps-7 | scroll-padding-inline-start: 1.75rem; | <div className="scroll-ps-7"></div> |
scroll-pe-7 | scroll-padding-inline-end: 1.75rem; | <div className="scroll-pe-7"></div> |
scroll-pt-7 | scroll-padding-top: 1.75rem; | <div className="scroll-pt-7"></div> |
scroll-pr-7 | scroll-padding-right: 1.75rem; | <div className="scroll-pr-7"></div> |
scroll-pb-7 | scroll-padding-bottom: 1.75rem; | <div className="scroll-pb-7"></div> |
scroll-pl-7 | scroll-padding-left: 1.75rem; | <div className="scroll-pl-7"></div> |
scroll-p-8 | scroll-padding: 2rem; | <div className="scroll-p-8"></div> |
scroll-px-8 | scroll-padding-left: 2rem;
scroll-padding-right: 2rem; | <div className="scroll-px-8"></div> |
scroll-py-8 | scroll-padding-top: 2rem;
scroll-padding-bottom: 2rem; | <div className="scroll-py-8"></div> |
scroll-ps-8 | scroll-padding-inline-start: 2rem; | <div className="scroll-ps-8"></div> |
scroll-pe-8 | scroll-padding-inline-end: 2rem; | <div className="scroll-pe-8"></div> |
scroll-pt-8 | scroll-padding-top: 2rem; | <div className="scroll-pt-8"></div> |
scroll-pr-8 | scroll-padding-right: 2rem; | <div className="scroll-pr-8"></div> |
scroll-pb-8 | scroll-padding-bottom: 2rem; | <div className="scroll-pb-8"></div> |
scroll-pl-8 | scroll-padding-left: 2rem; | <div className="scroll-pl-8"></div> |
scroll-p-9 | scroll-padding: 2.25rem; | <div className="scroll-p-9"></div> |
scroll-px-9 | scroll-padding-left: 2.25rem;
scroll-padding-right: 2.25rem; | <div className="scroll-px-9"></div> |
scroll-py-9 | scroll-padding-top: 2.25rem;
scroll-padding-bottom: 2.25rem; | <div className="scroll-py-9"></div> |
scroll-ps-9 | scroll-padding-inline-start: 2.25rem; | <div className="scroll-ps-9"></div> |
scroll-pe-9 | scroll-padding-inline-end: 2.25rem; | <div className="scroll-pe-9"></div> |
scroll-pt-9 | scroll-padding-top: 2.25rem; | <div className="scroll-pt-9"></div> |
scroll-pr-9 | scroll-padding-right: 2.25rem; | <div className="scroll-pr-9"></div> |
scroll-pb-9 | scroll-padding-bottom: 2.25rem; | <div className="scroll-pb-9"></div> |
scroll-pl-9 | scroll-padding-left: 2.25rem; | <div className="scroll-pl-9"></div> |
scroll-p-10 | scroll-padding: 2.5rem; | <div className="scroll-p-10"></div> |
scroll-px-10 | scroll-padding-left: 2.5rem;
scroll-padding-right: 2.5rem; | <div className="scroll-px-10"></div> |
scroll-py-10 | scroll-padding-top: 2.5rem;
scroll-padding-bottom: 2.5rem; | <div className="scroll-py-10"></div> |
scroll-ps-10 | scroll-padding-inline-start: 2.5rem; | <div className="scroll-ps-10"></div> |
scroll-pe-10 | scroll-padding-inline-end: 2.5rem; | <div className="scroll-pe-10"></div> |
scroll-pt-10 | scroll-padding-top: 2.5rem; | <div className="scroll-pt-10"></div> |
scroll-pr-10 | scroll-padding-right: 2.5rem; | <div className="scroll-pr-10"></div> |
scroll-pb-10 | scroll-padding-bottom: 2.5rem; | <div className="scroll-pb-10"></div> |
scroll-pl-10 | scroll-padding-left: 2.5rem; | <div className="scroll-pl-10"></div> |
scroll-p-11 | scroll-padding: 2.75rem; | <div className="scroll-p-11"></div> |
scroll-px-11 | scroll-padding-left: 2.75rem;
scroll-padding-right: 2.75rem; | <div className="scroll-px-11"></div> |
scroll-py-11 | scroll-padding-top: 2.75rem;
scroll-padding-bottom: 2.75rem; | <div className="scroll-py-11"></div> |
scroll-ps-11 | scroll-padding-inline-start: 2.75rem; | <div className="scroll-ps-11"></div> |
scroll-pe-11 | scroll-padding-inline-end: 2.75rem; | <div className="scroll-pe-11"></div> |
scroll-pt-11 | scroll-padding-top: 2.75rem; | <div className="scroll-pt-11"></div> |
scroll-pr-11 | scroll-padding-right: 2.75rem; | <div className="scroll-pr-11"></div> |
scroll-pb-11 | scroll-padding-bottom: 2.75rem; | <div className="scroll-pb-11"></div> |
scroll-pl-11 | scroll-padding-left: 2.75rem; | <div className="scroll-pl-11"></div> |
scroll-p-12 | scroll-padding: 3rem; | <div className="scroll-p-12"></div> |
scroll-px-12 | scroll-padding-left: 3rem;
scroll-padding-right: 3rem; | <div className="scroll-px-12"></div> |
scroll-py-12 | scroll-padding-top: 3rem;
scroll-padding-bottom: 3rem; | <div className="scroll-py-12"></div> |
scroll-ps-12 | scroll-padding-inline-start: 3rem; | <div className="scroll-ps-12"></div> |
scroll-pe-12 | scroll-padding-inline-end: 3rem; | <div className="scroll-pe-12"></div> |
scroll-pt-12 | scroll-padding-top: 3rem; | <div className="scroll-pt-12"></div> |
scroll-pr-12 | scroll-padding-right: 3rem; | <div className="scroll-pr-12"></div> |
scroll-pb-12 | scroll-padding-bottom: 3rem; | <div className="scroll-pb-12"></div> |
scroll-pl-12 | scroll-padding-left: 3rem; | <div className="scroll-pl-12"></div> |
scroll-p-14 | scroll-padding: 3.5rem; | <div className="scroll-p-14"></div> |
scroll-px-14 | scroll-padding-left: 3.5rem;
scroll-padding-right: 3.5rem; | <div className="scroll-px-14"></div> |
scroll-py-14 | scroll-padding-top: 3.5rem;
scroll-padding-bottom: 3.5rem; | <div className="scroll-py-14"></div> |
scroll-ps-14 | scroll-padding-inline-start: 3.5rem; | <div className="scroll-ps-14"></div> |
scroll-pe-14 | scroll-padding-inline-end: 3.5rem; | <div className="scroll-pe-14"></div> |
scroll-pt-14 | scroll-padding-top: 3.5rem; | <div className="scroll-pt-14"></div> |
scroll-pr-14 | scroll-padding-right: 3.5rem; | <div className="scroll-pr-14"></div> |
scroll-pb-14 | scroll-padding-bottom: 3.5rem; | <div className="scroll-pb-14"></div> |
scroll-pl-14 | scroll-padding-left: 3.5rem; | <div className="scroll-pl-14"></div> |
scroll-p-16 | scroll-padding: 4rem; | <div className="scroll-p-16"></div> |
scroll-px-16 | scroll-padding-left: 4rem;
scroll-padding-right: 4rem; | <div className="scroll-px-16"></div> |
scroll-py-16 | scroll-padding-top: 4rem;
scroll-padding-bottom: 4rem; | <div className="scroll-py-16"></div> |
scroll-ps-16 | scroll-padding-inline-start: 4rem; | <div className="scroll-ps-16"></div> |
scroll-pe-16 | scroll-padding-inline-end: 4rem; | <div className="scroll-pe-16"></div> |
scroll-pt-16 | scroll-padding-top: 4rem; | <div className="scroll-pt-16"></div> |
scroll-pr-16 | scroll-padding-right: 4rem; | <div className="scroll-pr-16"></div> |
scroll-pb-16 | scroll-padding-bottom: 4rem; | <div className="scroll-pb-16"></div> |
scroll-pl-16 | scroll-padding-left: 4rem; | <div className="scroll-pl-16"></div> |
scroll-p-20 | scroll-padding: 5rem; | <div className="scroll-p-20"></div> |
scroll-px-20 | scroll-padding-left: 5rem;
scroll-padding-right: 5rem; | <div className="scroll-px-20"></div> |
scroll-py-20 | scroll-padding-top: 5rem;
scroll-padding-bottom: 5rem; | <div className="scroll-py-20"></div> |
scroll-ps-20 | scroll-padding-inline-start: 5rem; | <div className="scroll-ps-20"></div> |
scroll-pe-20 | scroll-padding-inline-end: 5rem; | <div className="scroll-pe-20"></div> |
scroll-pt-20 | scroll-padding-top: 5rem; | <div className="scroll-pt-20"></div> |
scroll-pr-20 | scroll-padding-right: 5rem; | <div className="scroll-pr-20"></div> |
scroll-pb-20 | scroll-padding-bottom: 5rem; | <div className="scroll-pb-20"></div> |
scroll-pl-20 | scroll-padding-left: 5rem; | <div className="scroll-pl-20"></div> |
scroll-p-24 | scroll-padding: 6rem; | <div className="scroll-p-24"></div> |
scroll-px-24 | scroll-padding-left: 6rem;
scroll-padding-right: 6rem; | <div className="scroll-px-24"></div> |
scroll-py-24 | scroll-padding-top: 6rem;
scroll-padding-bottom: 6rem; | <div className="scroll-py-24"></div> |
scroll-ps-24 | scroll-padding-inline-start: 6rem; | <div className="scroll-ps-24"></div> |
scroll-pe-24 | scroll-padding-inline-end: 6rem; | <div className="scroll-pe-24"></div> |
scroll-pt-24 | scroll-padding-top: 6rem; | <div className="scroll-pt-24"></div> |
scroll-pr-24 | scroll-padding-right: 6rem; | <div className="scroll-pr-24"></div> |
scroll-pb-24 | scroll-padding-bottom: 6rem; | <div className="scroll-pb-24"></div> |
scroll-pl-24 | scroll-padding-left: 6rem; | <div className="scroll-pl-24"></div> |
scroll-p-28 | scroll-padding: 7rem; | <div className="scroll-p-28"></div> |
scroll-px-28 | scroll-padding-left: 7rem;
scroll-padding-right: 7rem; | <div className="scroll-px-28"></div> |
scroll-py-28 | scroll-padding-top: 7rem;
scroll-padding-bottom: 7rem; | <div className="scroll-py-28"></div> |
scroll-ps-28 | scroll-padding-inline-start: 7rem; | <div className="scroll-ps-28"></div> |
scroll-pe-28 | scroll-padding-inline-end: 7rem; | <div className="scroll-pe-28"></div> |
scroll-pt-28 | scroll-padding-top: 7rem; | <div className="scroll-pt-28"></div> |
scroll-pr-28 | scroll-padding-right: 7rem; | <div className="scroll-pr-28"></div> |
scroll-pb-28 | scroll-padding-bottom: 7rem; | <div className="scroll-pb-28"></div> |
scroll-pl-28 | scroll-padding-left: 7rem; | <div className="scroll-pl-28"></div> |
scroll-p-32 | scroll-padding: 8rem; | <div className="scroll-p-32"></div> |
scroll-px-32 | scroll-padding-left: 8rem;
scroll-padding-right: 8rem; | <div className="scroll-px-32"></div> |
scroll-py-32 | scroll-padding-top: 8rem;
scroll-padding-bottom: 8rem; | <div className="scroll-py-32"></div> |
scroll-ps-32 | scroll-padding-inline-start: 8rem; | <div className="scroll-ps-32"></div> |
scroll-pe-32 | scroll-padding-inline-end: 8rem; | <div className="scroll-pe-32"></div> |
scroll-pt-32 | scroll-padding-top: 8rem; | <div className="scroll-pt-32"></div> |
scroll-pr-32 | scroll-padding-right: 8rem; | <div className="scroll-pr-32"></div> |
scroll-pb-32 | scroll-padding-bottom: 8rem; | <div className="scroll-pb-32"></div> |
scroll-pl-32 | scroll-padding-left: 8rem; | <div className="scroll-pl-32"></div> |
scroll-p-36 | scroll-padding: 9rem; | <div className="scroll-p-36"></div> |
scroll-px-36 | scroll-padding-left: 9rem;
scroll-padding-right: 9rem; | <div className="scroll-px-36"></div> |
scroll-py-36 | scroll-padding-top: 9rem;
scroll-padding-bottom: 9rem; | <div className="scroll-py-36"></div> |
scroll-ps-36 | scroll-padding-inline-start: 9rem; | <div className="scroll-ps-36"></div> |
scroll-pe-36 | scroll-padding-inline-end: 9rem; | <div className="scroll-pe-36"></div> |
scroll-pt-36 | scroll-padding-top: 9rem; | <div className="scroll-pt-36"></div> |
scroll-pr-36 | scroll-padding-right: 9rem; | <div className="scroll-pr-36"></div> |
scroll-pb-36 | scroll-padding-bottom: 9rem; | <div className="scroll-pb-36"></div> |
scroll-pl-36 | scroll-padding-left: 9rem; | <div className="scroll-pl-36"></div> |
scroll-p-40 | scroll-padding: 10rem; | <div className="scroll-p-40"></div> |
scroll-px-40 | scroll-padding-left: 10rem;
scroll-padding-right: 10rem; | <div className="scroll-px-40"></div> |
scroll-py-40 | scroll-padding-top: 10rem;
scroll-padding-bottom: 10rem; | <div className="scroll-py-40"></div> |
scroll-ps-40 | scroll-padding-inline-start: 10rem; | <div className="scroll-ps-40"></div> |
scroll-pe-40 | scroll-padding-inline-end: 10rem; | <div className="scroll-pe-40"></div> |
scroll-pt-40 | scroll-padding-top: 10rem; | <div className="scroll-pt-40"></div> |
scroll-pr-40 | scroll-padding-right: 10rem; | <div className="scroll-pr-40"></div> |
scroll-pb-40 | scroll-padding-bottom: 10rem; | <div className="scroll-pb-40"></div> |
scroll-pl-40 | scroll-padding-left: 10rem; | <div className="scroll-pl-40"></div> |
scroll-p-44 | scroll-padding: 11rem; | <div className="scroll-p-44"></div> |
scroll-px-44 | scroll-padding-left: 11rem;
scroll-padding-right: 11rem; | <div className="scroll-px-44"></div> |
scroll-py-44 | scroll-padding-top: 11rem;
scroll-padding-bottom: 11rem; | <div className="scroll-py-44"></div> |
scroll-ps-44 | scroll-padding-inline-start: 11rem; | <div className="scroll-ps-44"></div> |
scroll-pe-44 | scroll-padding-inline-end: 11rem; | <div className="scroll-pe-44"></div> |
scroll-pt-44 | scroll-padding-top: 11rem; | <div className="scroll-pt-44"></div> |
scroll-pr-44 | scroll-padding-right: 11rem; | <div className="scroll-pr-44"></div> |
scroll-pb-44 | scroll-padding-bottom: 11rem; | <div className="scroll-pb-44"></div> |
scroll-pl-44 | scroll-padding-left: 11rem; | <div className="scroll-pl-44"></div> |
scroll-p-48 | scroll-padding: 12rem; | <div className="scroll-p-48"></div> |
scroll-px-48 | scroll-padding-left: 12rem;
scroll-padding-right: 12rem; | <div className="scroll-px-48"></div> |
scroll-py-48 | scroll-padding-top: 12rem;
scroll-padding-bottom: 12rem; | <div className="scroll-py-48"></div> |
scroll-ps-48 | scroll-padding-inline-start: 12rem; | <div className="scroll-ps-48"></div> |
scroll-pe-48 | scroll-padding-inline-end: 12rem; | <div className="scroll-pe-48"></div> |
scroll-pt-48 | scroll-padding-top: 12rem; | <div className="scroll-pt-48"></div> |
scroll-pr-48 | scroll-padding-right: 12rem; | <div className="scroll-pr-48"></div> |
scroll-pb-48 | scroll-padding-bottom: 12rem; | <div className="scroll-pb-48"></div> |
scroll-pl-48 | scroll-padding-left: 12rem; | <div className="scroll-pl-48"></div> |
scroll-p-52 | scroll-padding: 13rem; | <div className="scroll-p-52"></div> |
scroll-px-52 | scroll-padding-left: 13rem;
scroll-padding-right: 13rem; | <div className="scroll-px-52"></div> |
scroll-py-52 | scroll-padding-top: 13rem;
scroll-padding-bottom: 13rem; | <div className="scroll-py-52"></div> |
scroll-ps-52 | scroll-padding-inline-start: 13rem; | <div className="scroll-ps-52"></div> |
scroll-pe-52 | scroll-padding-inline-end: 13rem; | <div className="scroll-pe-52"></div> |
scroll-pt-52 | scroll-padding-top: 13rem; | <div className="scroll-pt-52"></div> |
scroll-pr-52 | scroll-padding-right: 13rem; | <div className="scroll-pr-52"></div> |
scroll-pb-52 | scroll-padding-bottom: 13rem; | <div className="scroll-pb-52"></div> |
scroll-pl-52 | scroll-padding-left: 13rem; | <div className="scroll-pl-52"></div> |
scroll-p-56 | scroll-padding: 14rem; | <div className="scroll-p-56"></div> |
scroll-px-56 | scroll-padding-left: 14rem;
scroll-padding-right: 14rem; | <div className="scroll-px-56"></div> |
scroll-py-56 | scroll-padding-top: 14rem;
scroll-padding-bottom: 14rem; | <div className="scroll-py-56"></div> |
scroll-ps-56 | scroll-padding-inline-start: 14rem; | <div className="scroll-ps-56"></div> |
scroll-pe-56 | scroll-padding-inline-end: 14rem; | <div className="scroll-pe-56"></div> |
scroll-pt-56 | scroll-padding-top: 14rem; | <div className="scroll-pt-56"></div> |
scroll-pr-56 | scroll-padding-right: 14rem; | <div className="scroll-pr-56"></div> |
scroll-pb-56 | scroll-padding-bottom: 14rem; | <div className="scroll-pb-56"></div> |
scroll-pl-56 | scroll-padding-left: 14rem; | <div className="scroll-pl-56"></div> |
scroll-p-60 | scroll-padding: 15rem; | <div className="scroll-p-60"></div> |
scroll-px-60 | scroll-padding-left: 15rem;
scroll-padding-right: 15rem; | <div className="scroll-px-60"></div> |
scroll-py-60 | scroll-padding-top: 15rem;
scroll-padding-bottom: 15rem; | <div className="scroll-py-60"></div> |
scroll-ps-60 | scroll-padding-inline-start: 15rem; | <div className="scroll-ps-60"></div> |
scroll-pe-60 | scroll-padding-inline-end: 15rem; | <div className="scroll-pe-60"></div> |
scroll-pt-60 | scroll-padding-top: 15rem; | <div className="scroll-pt-60"></div> |
scroll-pr-60 | scroll-padding-right: 15rem; | <div className="scroll-pr-60"></div> |
scroll-pb-60 | scroll-padding-bottom: 15rem; | <div className="scroll-pb-60"></div> |
scroll-pl-60 | scroll-padding-left: 15rem; | <div className="scroll-pl-60"></div> |
scroll-p-64 | scroll-padding: 16rem; | <div className="scroll-p-64"></div> |
scroll-px-64 | scroll-padding-left: 16rem;
scroll-padding-right: 16rem; | <div className="scroll-px-64"></div> |
scroll-py-64 | scroll-padding-top: 16rem;
scroll-padding-bottom: 16rem; | <div className="scroll-py-64"></div> |
scroll-ps-64 | scroll-padding-inline-start: 16rem; | <div className="scroll-ps-64"></div> |
scroll-pe-64 | scroll-padding-inline-end: 16rem; | <div className="scroll-pe-64"></div> |
scroll-pt-64 | scroll-padding-top: 16rem; | <div className="scroll-pt-64"></div> |
scroll-pr-64 | scroll-padding-right: 16rem; | <div className="scroll-pr-64"></div> |
scroll-pb-64 | scroll-padding-bottom: 16rem; | <div className="scroll-pb-64"></div> |
scroll-pl-64 | scroll-padding-left: 16rem; | <div className="scroll-pl-64"></div> |
scroll-p-72 | scroll-padding: 18rem; | <div className="scroll-p-72"></div> |
scroll-px-72 | scroll-padding-left: 18rem;
scroll-padding-right: 18rem; | <div className="scroll-px-72"></div> |
scroll-py-72 | scroll-padding-top: 18rem;
scroll-padding-bottom: 18rem; | <div className="scroll-py-72"></div> |
scroll-ps-72 | scroll-padding-inline-start: 18rem; | <div className="scroll-ps-72"></div> |
scroll-pe-72 | scroll-padding-inline-end: 18rem; | <div className="scroll-pe-72"></div> |
scroll-pt-72 | scroll-padding-top: 18rem; | <div className="scroll-pt-72"></div> |
scroll-pr-72 | scroll-padding-right: 18rem; | <div className="scroll-pr-72"></div> |
scroll-pb-72 | scroll-padding-bottom: 18rem; | <div className="scroll-pb-72"></div> |
scroll-pl-72 | scroll-padding-left: 18rem; | <div className="scroll-pl-72"></div> |
scroll-p-80 | scroll-padding: 20rem; | <div className="scroll-p-80"></div> |
scroll-px-80 | scroll-padding-left: 20rem;
scroll-padding-right: 20rem; | <div className="scroll-px-80"></div> |
scroll-py-80 | scroll-padding-top: 20rem;
scroll-padding-bottom: 20rem; | <div className="scroll-py-80"></div> |
scroll-ps-80 | scroll-padding-inline-start: 20rem; | <div className="scroll-ps-80"></div> |
scroll-pe-80 | scroll-padding-inline-end: 20rem; | <div className="scroll-pe-80"></div> |
scroll-pt-80 | scroll-padding-top: 20rem; | <div className="scroll-pt-80"></div> |
scroll-pr-80 | scroll-padding-right: 20rem; | <div className="scroll-pr-80"></div> |
scroll-pb-80 | scroll-padding-bottom: 20rem; | <div className="scroll-pb-80"></div> |
scroll-pl-80 | scroll-padding-left: 20rem; | <div className="scroll-pl-80"></div> |
scroll-p-96 | scroll-padding: 24rem; | <div className="scroll-p-96"></div> |
scroll-px-96 | scroll-padding-left: 24rem;
scroll-padding-right: 24rem; | <div className="scroll-px-96"></div> |
scroll-py-96 | scroll-padding-top: 24rem;
scroll-padding-bottom: 24rem; | <div className="scroll-py-96"></div> |
scroll-ps-96 | scroll-padding-inline-start: 24rem; | <div className="scroll-ps-96"></div> |
scroll-pe-96 | scroll-padding-inline-end: 24rem; | <div className="scroll-pe-96"></div> |
scroll-pt-96 | scroll-padding-top: 24rem; | <div className="scroll-pt-96"></div> |
scroll-pr-96 | scroll-padding-right: 24rem; | <div className="scroll-pr-96"></div> |
scroll-pb-96 | scroll-padding-bottom: 24rem; | <div className="scroll-pb-96"></div> |
scroll-pl-96 | scroll-padding-left: 24rem; | <div className="scroll-pl-96"></div> |
Overview of Scroll Padding
Adding the Scroll Padding
To set scroll padding in Tailwind CSS, you can use any of the predefined classes. These classes are appended with numerical values and logical directions such as top (t
), left (l
), right (r
), bottom (b
), and all sides (p
), e.g., scroll-p-2
, scroll-p-3
, scroll-p-4
, etc.
export default function ScrollPaddingDemo() { return ( <div className="snap-y scroll-pt-10 snap-mandatory flex flex-col gap-4 items-center overflow-auto h-screen px-10 pt-10 bg-gray-50"> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1511467687858-23d96c32e4ae" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1487017159836-4e23ece2e4cf" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1489269637500-aa0e75768394" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1488998427799-e3362cec87c3" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1527443224154-c4a3942d3acf" className="w-full h-full object-cover shadow-md" /> </div> </div> ); }
Leveraging Logical Properties
To set logical scroll padding properties like scroll-padding-inline-start
and scroll-padding-inline-end
, use the scroll-ps-*
and scroll-pe-*
utilities. These utilities apply the scroll padding based on the text direction- left to right or right to left.
export default function LogicalPropertiesDemo() { return ( <div dir="rtl" className="snap-x scroll-ps-10 snap-mandatory flex gap-4 items-center overflow-auto w-full h-screen px-10 bg-gray-50"> <div className="snap-start min-w-72 h-48"> <img src="https://images.unsplash.com/photo-1511467687858-23d96c32e4ae" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start min-w-72 h-48"> <img src="https://images.unsplash.com/photo-1487017159836-4e23ece2e4cf" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start min-w-72 h-48"> <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start min-w-72 h-48"> <img src="https://images.unsplash.com/photo-1489269637500-aa0e75768394" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start min-w-72 h-48"> <img src="https://images.unsplash.com/photo-1488998427799-e3362cec87c3" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start min-w-72 h-48"> <img src="https://images.unsplash.com/photo-1527443224154-c4a3942d3acf" className="w-full h-full object-cover shadow-md" /> </div> </div> ); }
States and Responsiveness
Hover and Focus States
Tailwind also provides state modifiers to conditionally apply scroll padding. To apply scroll padding on states such as hover
or focus
, prepend the modifiers to the utilities, e.g., hover:scroll-pt-*
, hover:scroll-pb-*
, etc.
export default function HoverDemo() { return ( <div className="snap-y hover:scroll-pt-10 snap-mandatory flex flex-col gap-4 items-center overflow-auto h-screen px-10 pt-10 bg-gray-50"> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1511467687858-23d96c32e4ae" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1487017159836-4e23ece2e4cf" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1489269637500-aa0e75768394" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1488998427799-e3362cec87c3" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1527443224154-c4a3942d3acf" className="w-full h-full object-cover shadow-md" /> </div> </div> ); }
Breakpoint Modifiers
Tailwind lets you apply scroll padding to different screen sizes by using breakpoint modifiers- sm
, md
, lg
, etc. To apply scroll padding on specific breakpoints, prepend the modifiers to the utilities, e.g., md:scroll-pt-*
, lg:scroll-pb-*
, etc.
export default function ResponsivePadding() { return ( <div className="snap-y scroll-pt-4 sm:scroll-pt-8 lg:scroll-pt-12 snap-mandatory flex flex-col gap-4 items-center overflow-auto h-screen px-10 pt-10 bg-gray-50"> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1511467687858-23d96c32e4ae" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1487017159836-4e23ece2e4cf" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1489269637500-aa0e75768394" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1488998427799-e3362cec87c3" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1527443224154-c4a3942d3acf" className="w-full h-full object-cover shadow-md" /> </div> </div> ); }
Custom Scroll Padding
You can define scroll padding values outside the default Tailwind configuration using custom themes or arbitrary value utilities to better reflect your design needs.
Extending the Theme
By using the extend
key in your Tailwind configuration object, custom scroll padding values can be added to your project. Once configured, you can use these new values:
import tailwindConfig from "./tailwind.config.js"; tailwind.config = tailwindConfig; export default function ThemeExtension() { return ( <div className="snap-y scroll-pt-3xs snap-mandatory flex flex-col gap-4 items-center overflow-auto h-screen px-10 pt-10 bg-gray-50"> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1511467687858-23d96c32e4ae" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1487017159836-4e23ece2e4cf" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1489269637500-aa0e75768394" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1488998427799-e3362cec87c3" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1527443224154-c4a3942d3acf" className="w-full h-full object-cover shadow-md" /> </div> </div> ); }
Using Arbitrary Values
For one-off cases, where predefined utilities are not enough and customizing the theme is too much effort, you can use the arbitrary values. Here, custom values are passed directly in square brackets, making them quick to use without customization in the config file.
export default function ArbitraryPadding() { return ( <div className="snap-y scroll-pt-[20px] snap-mandatory flex flex-col gap-4 items-center overflow-auto h-screen px-10 pt-10 bg-gray-50"> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1511467687858-23d96c32e4ae" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1487017159836-4e23ece2e4cf" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1508873699372-7aeab60b44ab" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1489269637500-aa0e75768394" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1488998427799-e3362cec87c3" className="w-full h-full object-cover shadow-md" /> </div> <div className="snap-start h-96"> <img src="https://images.unsplash.com/photo-1527443224154-c4a3942d3acf" className="w-full h-full object-cover shadow-md" /> </div> </div> ); }
Real World Examples
Product Category Navigation
A horizontal scrolling product category navigation with scroll padding to ensure better visibility of items at the edges.
export default function CategoryScroller() { const categories = [ { id: 1, name: "Electronics", icon: "https://images.unsplash.com/photo-1518770660439-4636190af475" }, { id: 2, name: "Fashion", icon: "https://plus.unsplash.com/premium_photo-1664202526559-e21e9c0fb46a" }, { id: 3, name: "Home", icon: "https://images.unsplash.com/photo-1480074568708-e7b720bb3f09" }, { id: 4, name: "Sports", icon: "https://images.unsplash.com/photo-1612872087720-bb876e2e67d1" }, { id: 5, name: "Books", icon: "https://images.unsplash.com/photo-1495446815901-a7297e633e8d" }, { id: 6, name: "Beauty", icon: "https://images.unsplash.com/photo-1522335789203-aabd1fc54bc9" }, { id: 7, name: "Garden", icon: "https://images.unsplash.com/photo-1585320806297-9794b3e4eeae" } ]; return ( <div className="scroll-pl-6 snap-x snap-mandatory overflow-x-auto flex gap-4 pb-4"> {categories.map((category) => ( <div key={category.id} className="snap-center shrink-0"> <div className="w-24 h-24 rounded-full overflow-hidden p-2"> <img src={category.icon} alt={category.name} className="w-full h-full object-cover rounded-full" /> </div> <p className="text-center mt-2">{category.name}</p> </div> ))} </div> ); }
Recipe Steps Carousel
A vertical scrolling carousel showing cooking recipe steps with images and instructions.
const RecipeSteps = () => { const steps = [ { id: 1, title: "Prepare Ingredients", description: "Gather all ingredients and chop vegetables", src: "https://images.unsplash.com/photo-1556911220-e15b29be8c8f", alt: "Chopped vegetables on cutting board" }, { id: 2, title: "Mix Ingredients", description: "Combine all ingredients in a large bowl", src: "https://images.unsplash.com/photo-1563805042-7684c019e1cb", alt: "Mixing ingredients in bowl" }, { id: 3, title: "Preheat Oven", description: "Set oven temperature to 350°F (175°C)", src: "https://images.unsplash.com/photo-1585747860715-2ba37e788b70", alt: "Oven preheating" }, { id: 4, title: "Prepare Pan", description: "Grease baking pan with butter", src: "https://images.unsplash.com/photo-1612528443702-f6741f70a049", alt: "Greasing baking pan" }, { id: 5, title: "Bake", description: "Place in oven and bake for 30 minutes", src: "https://images.unsplash.com/photo-1572279990716-4f8343703ed6", alt: "Baking in oven" }, { id: 6, title: "Cool Down", description: "Let it cool for 10 minutes before serving", src: "https://images.unsplash.com/photo-1556679343-c7306c1976bc", alt: "Cooling on rack" } ]; return ( <div className="bg-gray-50 h-[500px]"> <div className="h-full overflow-y-auto scroll-pt-6 snap-y snap-mandatory"> {steps.map((step) => ( <div key={step.id} className="snap-start h-[calc(100%-48px)] p-6" > <div className="bg-white rounded-xl overflow-hidden shadow-md h-full"> <div className="h-1/2"> <img src={step.src} alt={step.alt} className="w-full h-full object-cover" /> </div> <div className="p-6"> <h3 className="text-xl font-bold mb-2">{step.title}</h3> <p className="text-gray-600">{step.description}</p> </div> </div> </div> ))} </div> </div> ); }; export default RecipeSteps;
Image Gallery
A responsive image gallery with scroll padding for better viewing experience.
export default function ImageGallery() { const images = [ { id: 1, src: "https://images.unsplash.com/photo-1421789665209-c9b2a435e3dc", alt: "Nature" }, { id: 2, src: "https://images.unsplash.com/photo-1435575653489-b0873ec954e2", alt: "Architecture" }, { id: 3, src: "https://images.unsplash.com/photo-1469854523086-cc02fe5d8800", alt: "Travel" }, { id: 4, src: "https://images.unsplash.com/photo-1512621776951-a57141f2eefd", alt: "Food" }, { id: 5, src: "https://images.unsplash.com/photo-1531297484001-80022131f5a1", alt: "Technology" }, { id: 6, src: "https://images.unsplash.com/photo-1456926631375-92c8ce872def", alt: "Animals" } ]; return ( <div className="scroll-pl-8 snap-x snap-mandatory overflow-x-auto flex gap-6 p-8"> {images.map((image) => ( <div key={image.id} className="snap-center shrink-0 first:pl-8 last:pr-8"> <img src={image.src} alt={image.alt} className="w-80 h-60 object-cover rounded-lg shadow-lg" /> </div> ))} </div> ); }
Social Media Stories Carousel
A horizontal scrolling carousel for social media stories with profile images and names.
const StoriesCarousel = () => { const stories = [ { id: 1, name: "Emma Watson", src: "https://images.unsplash.com/photo-1544005313-94ddf0286df2", alt: "Profile of Emma Watson" }, { id: 2, name: "John Blake", src: "https://images.unsplash.com/photo-1547425260-76bcadfb4f2c", alt: "Profile of John Blake" }, { id: 3, name: "Sarah Chen", src: "https://images.unsplash.com/photo-1554151228-14d9def656e4", alt: "Profile of Sarah Chen" }, { id: 4, name: "Mike Ross", src: "https://images.unsplash.com/photo-1552058544-f2b08422138a", alt: "Profile of Mike Ross" }, { id: 5, name: "Lisa Park", src: "https://images.unsplash.com/photo-1545912452-8aea7e25a3d3", alt: "Profile of Lisa Park" }, { id: 6, name: "Tom Cruz", src: "https://images.unsplash.com/photo-1548142813-c348350df52b", alt: "Profile of Tom Cruz" } ]; return ( <div className="w-full p-4 bg-gray-100"> <div className="overflow-x-auto scrollbar-hide scroll-pl-12 snap-x snap-mandatory"> <div className="flex gap-12 pb-4"> {stories.map((story) => ( <div key={story.id} className="flex-none w-16 snap-start" > <div className="w-16 h-16 rounded-full ring-2 ring-blue-500 overflow-hidden"> <img src={story.src} alt={story.alt} className="w-full h-full object-cover" /> </div> <p className="text-xs text-center mt-1 truncate">{story.name}</p> </div> ))} </div> </div> </div> ); }; export default StoriesCarousel;
Product Card Carousel
A horizontal scrolling product card carousel with scroll padding for better product visibility.
export default function ProductCarousel() { const products = [ { id: 1, name: "Wireless Headphones", price: "$299", image: "https://images.unsplash.com/photo-1546435770-a3e426bf472b", alt: "Wireless Headphones" }, { id: 2, name: "Smart Watch", price: "$199", image: "https://images.unsplash.com/photo-1579586337278-3befd40fd17a", alt: "Smart Watch" }, { id: 3, name: "Laptop", price: "$999", image: "https://images.unsplash.com/photo-1496181133206-80ce9b88a853", alt: "Laptop" }, { id: 4, name: "Smartphone", price: "$799", image: "https://images.unsplash.com/photo-1533228100845-08145b01de14", alt: "Smartphone" }, { id: 5, name: "Tablet", price: "$499", image: "https://images.unsplash.com/photo-1527698266440-12104e498b76", alt: "Tablet" }, { id: 6, name: "Camera", price: "$699", image: "https://images.unsplash.com/photo-1502920917128-1aa500764cbd", alt: "Camera" } ]; return ( <div className="scroll-pl-6 scroll-pr-6 snap-x snap-mandatory overflow-x-auto flex gap-6 p-6"> {products.map((product) => ( <div key={product.id} className="snap-center shrink-0 w-72 bg-white rounded-xl shadow-lg" > <img src={product.image} alt={product.alt} className="w-full h-48 object-cover rounded-t-xl" /> <div className="p-4"> <h3 className="text-lg font-semibold">{product.name}</h3> <p className="text-blue-600 font-bold mt-2">{product.price}</p> <button className="w-full mt-4 bg-blue-500 text-white py-2 rounded-lg hover:bg-blue-600"> Add to Cart </button> </div> </div> ))} </div> ); }
Customization Examples
Horizontal Image Gallery
A horizontal scrolling image gallery with custom scroll padding on left side.
import tailwindConfig from "./tailwind.config.js"; tailwind.config = tailwindConfig; const HorizontalGallery = () => { return ( <div className="w-full overflow-x-auto snap-x snap-mandatory scroll-pl-edge"> <div className="flex gap-4 py-4"> {Array.from({ length: 6 }).map((_, i) => ( <img key={i} src="https://images.unsplash.com/photo-1503455637927-730bce8583c0" alt="Pattern" className="w-64 h-48 rounded-lg snap-center flex-none object-cover" /> ))} </div> </div> ) } export default HorizontalGallery;
Vertical Article List
A vertically scrolling article list with custom top scroll padding to account for a fixed header.
import tailwindConfig from "./tailwind.config.js"; tailwind.config = tailwindConfig; const ArticleList = () => { return ( <div className="h-screen"> <header className="fixed top-0 w-full bg-white shadow-md p-4 z-10"> <h1 className="text-xl font-bold">Articles</h1> </header> <div className="h-full overflow-y-auto snap-y snap-mandatory scroll-pt-header"> {Array.from({ length: 5 }).map((_, i) => ( <article key={i} className="snap-start min-h-[80vh] p-6 border-b flex flex-col gap-4" > <img src="https://images.unsplash.com/photo-1588345921523-c2dcdb7f1dcd" alt="Article Cover" className="w-full h-48 object-cover rounded-lg" /> <h2 className="text-lg font-semibold">Article Title {i + 1}</h2> <p className="text-gray-600"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p> </article> ))} </div> </div> ) } export default ArticleList;
Vertical Product Cards with Bottom Scroll Margin
A vertical scrolling product list with bottom padding to ensure the last card is fully visible.
import tailwindConfig from "./tailwind.config.js"; tailwind.config = tailwindConfig; // App.js const ProductList = () => { const products = [ { title: "Premium Headphones", price: "$299", src: "https://images.unsplash.com/photo-1546435770-a3e426bf472b" }, { title: "Wireless Speaker", price: "$199", src: "https://images.unsplash.com/photo-1561558834-3b6b2aa22b6a" }, { title: "Smart Watch", price: "$399", src: "https://images.unsplash.com/photo-1619037961428-e6410a7afd38" }, { title: "Fitness Tracker", price: "$149", src: "https://images.unsplash.com/photo-1576243345690-4e4b79b63288" } ]; return ( <div className="h-screen overflow-y-auto scroll-pt-top-middle snap-y snap-mandatory"> {products.map((product, index) => ( <div key={index} className="p-6 mb-4 bg-white rounded-lg shadow-lg snap-start min-h-[200px]" > <img src={product.src} alt={product.title} className="w-full h-40 object-cover rounded-md mb-4" /> <h3 className="text-xl font-bold">{product.title}</h3> <p className="text-gray-600">{product.price}</p> </div> ))} </div> ); }; export default ProductList;
Best Practices
Maintain Design Consistency
When working with scroll padding in Tailwind CSS, it’s crucial to apply uniform padding across related elements to maintain a harmonious look and feel. For example, when dealing with a cards section, ensure the same scroll padding applies to all similar scrollable containers. This prevents misalignment and ensures visual consistency throughout the interface.
Additionally, consider using Tailwind's theme extension to centralize custom scroll padding values, making it easier to reuse and adapt throughout your project. By adhering to consistent spacing guidelines, you ensure an intuitive, aesthetically balanced experience for users navigating your application.
Build Responsive Design
Responsive design plays a vital role in ensuring a seamless user experience across different devices. Tailwind's responsive variants allow developers to adjust scroll-padding
dynamically based on screen size. This prevents content from being excessively spaced on smaller screens while maintaining clarity on larger displays.
To implement responsive scroll padding, use variants such as sm:scroll-p-4
, md:scroll-p-8
, lg:scroll-p-12
, etc. This ensures that padding values adapt to different screen widths, optimizing readability and usability. A good approach is setting a baseline padding for mobile devices and scaling it accordingly for desktops.
Accessibility Considerations
Enhance Readability and Navigability
Applying scroll-padding
strategically improves both readability and content navigability. When users scroll through a page, properly spaced content ensures that elements remain easy to read without feeling cramped. This is particularly important for long text-based sections where adequate spacing enhances the reading experience.
For navigational elements, scroll-padding
can be used to ensure that anchor links do not align too closely to the top of the viewport, which could obscure text under a fixed header.
Ensure Keyboard Accessibility
Keyboard navigation should be prioritized when implementing scroll-padding
to ensure that users who navigate with the Tab key can access interactive elements seamlessly. When defining scrollable areas, it’s essential to configure the layout so that focusable elements remain within the viewport.
Using scroll-padding
strategically helps align these focusable elements properly. This prevents them from being hidden behind fixed headers or other overlapping content, ensuring that users maintain a clear navigation path. Additionally, testing with keyboard-only navigation tools is also crucial to identify and address any issues with focus positioning in scrollable sections, thereby improving overall accessibility.