Browse documentation

Reference / Interactivity

Scroll margin

Give an individual scroll target clearance when it is snapped into position or reached by a browser scroll operation.

Working example

Scroll margin belongs to the target. Here each swatch has an inline-start margin to leave space before its snapped edge.

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

Class reference

ClassCSS declarations
scroll-m-4scroll-margin: 1rem;
scroll-mt-16scroll-margin-top: 4rem;
scroll-ms-4scroll-margin-inline-start: 1rem;
scroll-mx-3scroll-margin-inline: 0.75rem;
scroll-mb-[2rem]scroll-margin-bottom: 2rem;
View full generated CSS
Compiled CSS
.scroll-m-4 {
  scroll-margin: 1rem;
}
.scroll-mx-3 {
  scroll-margin-inline: 0.75rem;
}
.scroll-mb-\[2rem\] {
  scroll-margin-bottom: 2rem;
}
.scroll-ms-4 {
  scroll-margin-inline-start: 1rem;
}
.scroll-mt-16 {
  scroll-margin-top: 4rem;
}