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
Paper sample
First fold
Second fold
Final trim
Scroll inside this sample to move the ruling together with the lines. A fixed attachment instead positions its background relative to the viewport.
<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
| Class | CSS declarations |
|---|---|
bg-local | background-attachment: local; |
bg-scroll | background-attachment: scroll; |
bg-fixed | background-attachment: fixed; |
View full generated CSS
.bg-fixed {
background-attachment: fixed;
}
.bg-local {
background-attachment: local;
}
.bg-scroll {
background-attachment: scroll;
}