Browse documentation

Reference / Backgrounds

Background attachment

Control whether a painted background moves with an element’s content or stays anchored as the content scrolls.

Working example

Scroll inside this sample to move the ruling together with the lines. A fixed attachment instead positions its background relative to the viewport.

HTML
<div tabindex="0" role="region" aria-label="Scrollable paper sample"
  class="h-20 overflow-auto border bg-local bg-[repeating-linear-gradient(white_0_23px,#bbb_23px_24px)] p-2">
  <p class="h-40 leading-6">Paper sample<br>First fold<br>Second fold<br>Final trim</p>
</div>

Class reference

ClassCSS declarations
bg-localbackground-attachment: local;
bg-scrollbackground-attachment: scroll;
bg-fixedbackground-attachment: fixed;
View full generated CSS
Compiled CSS
.bg-fixed {
  background-attachment: fixed;
}
.bg-local {
  background-attachment: local;
}
.bg-scroll {
  background-attachment: scroll;
}