1. Backgrounds
  2. background-attachment

Backgrounds

background-attachment

Utilities for setting how a background image responds as the page scrolls.

ClassStyles
bg-fixed
background-attachment: fixed;
bg-local
background-attachment: local;
bg-scroll
background-attachment: scroll;

Examples

Pinning the background image

Reach for the bg-fixed utility to anchor the background image relative to the viewport:

Scroll the content below to see the background image locked in place

November 16, 2021 · 4 min read

Perhaps we could get by without a single framework, folks like you and me. Perhaps. Sure, we're too set in our ways to reinvent the whole stack, but what about that newcomer, sitting down, opening an editor, right now, in some quiet corner of the web and stumbling onto tangled spaghetti and copy-pasted hacks in every file? Doesn't SHE deserve better?

Look. If you think this is about shaving a few kilobytes and trimming a build step, you'd better think again. This is about that newcomer's right to ship a project without her momentum getting crushed! Or: maybe that thrills you, friend; maybe that's how you get your kicks. You and your late-night crew.

<div class="bg-[url(/img/mountains.jpg)] bg-fixed ...">  <!-- ... --></div>

Scrolling inside the container

Reach for the bg-local utility to scroll the background image with both the container and the viewport:

Scroll through the panel to watch the background image move with the container

Because the notifications never stop. They just keep arriving and arriving and arriving, there's never a break. It's relentless. Every single day there are more and more and more. And you clear them out but the more you clear them out the more they keep coming back. And then the sync service falls over and it's launch day all over again.

— Marlow
<div class="bg-[url(/img/mountains.jpg)] bg-local ...">  <!-- ... --></div>

Moving with the viewport

Reach for the bg-scroll utility to move the background image with the viewport while leaving the container fixed:

Scroll through the panel to watch the background image stay fixed in place

Because the notifications never stop. They just keep arriving and arriving and arriving, there's never a break. It's relentless. Every single day there are more and more and more. And you clear them out but the more you clear them out the more they keep coming back. And then the sync service falls over and it's launch day all over again.

— Marlow
<div class="bg-[url(/img/mountains.jpg)] bg-scroll ...">  <!-- ... --></div>

Responsive behavior

Add a breakpoint variant such as md: in front of any background-attachment utility so it applies only at medium screen sizes and above:

<div class="bg-local md:bg-fixed ...">  <!-- ... --></div>

Read more about how variants work in the variants usage guide.

Copyright © 2026 Breezel, Inc.·Trademark Policy