Background Position

Utilities for controlling the position of an element's background image.

Class reference

Class Properties
.bg-bottom background-position: bottom;
.bg-center background-position: center;
.bg-left background-position: left;
.bg-left-bottom background-position: left bottom;
.bg-left-top background-position: left top;
.bg-right background-position: right;
.bg-right-bottom background-position: right bottom;
.bg-right-top background-position: right top;
.bg-top background-position: top;

Usage

Use the .bg-{side} utilities to control the position of an element's background image.

.bg-left-top

.bg-top

.bg-right-top

.bg-left

.bg-center

.bg-right

.bg-left-bottom

.bg-bottom

.bg-right-bottom

<div class="bg-no-repeat bg-left-top bg-gray-400 w-24 h-24" style="background-image: url(...);"></div>
<div class="bg-no-repeat bg-top bg-gray-400 w-24 h-24" style="background-image: url(...);"></div>
<div class="bg-no-repeat bg-right-top bg-gray-400 w-24 h-24" style="background-image: url(...);"></div>
<div class="bg-no-repeat bg-left bg-gray-400 w-24 h-24" style="background-image: url(...);"></div>
<div class="bg-no-repeat bg-center bg-gray-400 w-24 h-24" style="background-image: url(...);"></div>
<div class="bg-no-repeat bg-right bg-gray-400 w-24 h-24" style="background-image: url(...);"></div>
<div class="bg-no-repeat bg-left-bottom bg-gray-400 w-24 h-24" style="background-image: url(...);"></div>
<div class="bg-no-repeat bg-bottom bg-gray-400 w-24 h-24" style="background-image: url(...);"></div>
<div class="bg-no-repeat bg-right-bottom bg-gray-400 w-24 h-24" style="background-image: url(...);"></div>

Responsive

To control the position of an element's background image at a specific breakpoint, add a {screen}: prefix to any existing background position utility. For example, adding the class md:bg-top to an element would apply the bg-top utility at medium screen sizes and above.

For more information about Tailwind's responsive design features, check out the Responsive Design documentation.

Customizing

Background Positions

By default Tailwind provides nine background-position utilities. You change, add, or remove these by editing the theme.backgroundPosition section of your Tailwind config.

// tailwind.config.js
module.exports = {
theme: {
backgroundPosition: {
      bottom: 'bottom',
+     'bottom-4': 'center bottom 1rem',
      center: 'center',
      left: 'left',
-     'left-bottom': 'left bottom',
-     'left-top': 'left top',
      right: 'right',
      'right-bottom': 'right bottom',
      'right-top': 'right top',
      top: 'top',
+     'top-4': 'center top 1rem',
}
}
}

Responsive and State Variants

By default, only responsive variants are generated for background position utilities.

You can control which variants are generated for the background position utilities by modifying the backgroundPosition property in the variants section of your tailwind.config.js file.

For example, this config will also generate hover and focus variants:

// tailwind.config.js
module.exports = {
variants: {
    // ...
-   backgroundPosition: ['responsive'],
+   backgroundPosition: ['responsive', 'hover', 'focus'],
}
}

Disabling

If you don't plan to use the background position utilities in your project, you can disable them entirely by setting the backgroundPosition property to false in the corePlugins section of your config file:

// tailwind.config.js
module.exports = {
corePlugins: {
    // ...
+   backgroundPosition: false,
}
}