Last updated: 13 March 2025

Tailwind Background Attachment

The bg-{attachment} utility class in Tailwind CSS allows you to control the attachment behavior of background images applied to elements.


Tailwind Backgound Attachment

The bg-{attachment} utility class in Tailwind CSS allows you to control the attachment behavior of background images applied to elements. With Tailwind's bg-{attachment} class, you can easily adjust whether the background image scrolls with the content or stays fixed within the element.

How to apply Tailwind Background Attachment

To apply a specific tailwind background attachment behavior to an element, you can use the bg-{attachment} utility class, where {attachment} represents the desired background attachment. Here are the common values you can use:

  • bg-fixed: The background image is fixed and does not scroll with the content.
  • bg-local: The background image scrolls with the content of the element.
  • bg-scroll: The background image scrolls with the content of the element, even when the element itself is scrolled. Here's an example:
html
<div class="bg-fixed"></div>

Preview

My Trip to the Caribbean

November 18, 2019

During my trip to the Caribbean, I had the pleasure of enjoying sunny weather and a stunning inland location with breathtaking water views.The natural beauty of the surroundings, combined with the peaceful atmosphere and clear skies, made it a truly remarkable experience. The locals were incredibly friendly and hospitable, adding to the warm and welcoming ambiance of the place.

What’s Happening Here:

  • bg-fixed: Keeps the background static as you scroll.

  • overflow-y-scroll: Allows the content inside the card to scroll.

  • bg-cover and bg-center: Make sure the background image covers the whole element and is centered.

This is a simple and elegant way to create a visually striking section.

Why Background Attachment Matters in Design

Understanding how background attachment works can help you design smoother and more professional-looking layouts. It allows you to:

  • Fix decorative images while content scrolls

  • Create parallax-like effects without JavaScript

  • Improve readability by controlling how backgrounds move in relation to text

Responsive Tailwind Background Attachment

Tailwind CSS allows you to apply background attachment classes responsively at different breakpoints. To use responsive tailwind background attachment classes, you can append the breakpoint prefix to the utility class. For example, md:bg-scroll sets the background attachment to scroll starting from the medium breakpoint and above.

html
<div class="bg-local md:bg-scroll">
This element has a background image that scrolls with the content by
default, but starting from the medium breakpoint and above, it changes to be
fixed.
</div>

In the above example, the background attachment of the <div> element is set to local (scrolls with the content) by default (bg-local), but starting from the medium breakpoint and above, it changes to be fixed (md:bg-scroll).

When to Use Each Tailwind Background Attachment Class

  • 🔹 bg-fixed Use it for parallax-like effects where the background image stays in place as users scroll through content. Ideal for hero sections, banners, or full-page backgrounds.

  • 🔹 bg-local Use when you want the background image to move along with the content inside a scrollable container. Great for cards, modals, and article blocks.

  • 🔹 bg-scroll This is the default behavior. Use it when no special effect is needed, or when designing content-heavy pages.

Accessibility and Performance Tips

  • 🧠 Use alt text on background images when possible (if using inline images for decoration, it’s okay to leave alt blank).

  • ⚡ Compress large images to avoid slow page load times, especially when using bg-fixed.

  • 💡 Consider adding an overlay (bg-black bg-opacity-50) to improve text readability over busy backgrounds.

Tailwind Background Attachemnt Class Table

ClassProperties
bg-fixedbackground-attachment: fixed;
bg-localbackground-attachment: local;
bg-scrollbackground-attachment: scroll;

Windframe Tailwind blocks

Timeline

Windframe is a drag and drop builder for rapidly building tailwind css websites and UIs

Start building stunning tailwind UIs! 

Build from scratch or select prebuilt tailwind templates