Browse documentation

Reference / Interactivity

Scroll padding

Inset the optimal viewing region of a scrolling container so its targets settle away from the edges.

Working example

Set scroll padding on the scroller to apply a shared inset. Targets can then use the same simple snap-start alignment.

HTML
<div tabindex="0" role="region" aria-label="Scroll padding sample"
  class="flex w-48 max-w-full gap-3 overflow-x-auto border p-2 snap-x snap-mandatory scroll-px-4">
  <div class="w-32 shrink-0 bg-neutral-100 p-4 snap-start">Paper</div>
  <div class="w-32 shrink-0 bg-neutral-800 p-4 text-white snap-start">Carbon</div>
  <div class="w-32 shrink-0 bg-neutral-200 p-4 snap-start">Stone</div>
</div>

Class reference

ClassCSS declarations
scroll-p-4scroll-padding: 1rem;
scroll-pt-16scroll-padding-top: 4rem;
scroll-px-4scroll-padding-inline: 1rem;
scroll-pe-4scroll-padding-inline-end: 1rem;
scroll-py-[1rem]scroll-padding-block: 1rem;
View full generated CSS
Compiled CSS
.scroll-p-4 {
  scroll-padding: 1rem;
}
.scroll-px-4 {
  scroll-padding-inline: 1rem;
}
.scroll-py-\[1rem\] {
  scroll-padding-block: 1rem;
}
.scroll-pe-4 {
  scroll-padding-inline-end: 1rem;
}
.scroll-pt-16 {
  scroll-padding-top: 4rem;
}