Last updated: 17 May 2024

Tailwind CSS Background Origin

The bg-{origin} utility class in Tailwind CSS allows you to control the position origin of background images applied to elements. With Tailwind background origin class, you can easily adjust where the background image originates within the element box model.


Tailwind Background Origin

The bg-{origin} utility class in Tailwind CSS allows you to control the position origin of background images applied to elements. With Tailwind background origin class, you can easily adjust where the background image originates within the element's box model.

Applying Tailwind Background Origin

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

  • bg-origin-border: The background image originates from the border box.
  • bg-origin-padding: The background image originates from the padding box.
  • bg-origin-content: The background image originates from the content box. Here's an example:
html
<div class="bg-origin-padding">
This element has a background image that originates from the padding box.
</div>

Preview

This element has a background image that originates from the padding box.

Responsive Tailwind Background Origin

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

html
<div class="bg-origin-border md:bg-origin-content">
This element has a background image that originates from the border box by
default, but starting from the medium breakpoint and above, it changes to
originate from the content box.
</div>

In the above example, the tailwind background origin of the <div> element is set to the border box by default (bg-origin-border), but starting from the medium breakpoint and above, it changes to originate from the content box (md:bg-origin-content).

Tailwind Background Origin Class Table

ClassProperties
bg-origin-borderbackground-origin: border-box;
bg-origin-paddingbackground-origin: padding-box;
bg-origin-contentbackground-origin: content-box;

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