Tailwind CSS v1.0 is here! Learn more →

Background Size

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

Work in progress!

More detailed documentation is coming soon, but in the meantime here's a quick class reference.

Class reference

Class Properties
.bg-auto background-size: auto;
.bg-cover background-size: cover;
.bg-contain background-size: contain;

Customizing

By default Tailwind provides utilities for auto, cover, and contain background sizes. You can change, add, or remove these by editing the backgroundSize section of your config.

{
// ...
backgroundSize: {
    'auto': 'auto',
    'cover': 'cover',
    'contain': 'contain',
+   '50%': '50%',
+   '16': '4rem',
}
}

Responsive and State Variants

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

You can control which variants are generated for the background size utilities by modifying the backgroundSize property in the modules section of your Tailwind config file.

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

{
// ...
modules: {
    // ...
-   backgroundSize: ['responsive'],
+   backgroundSize: ['responsive', 'hover', 'focus', 'active', 'group-hover'],
}
}

Disabling

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

{
// ...
modules: {
    // ...
-   backgroundSize: ['responsive'],
+   backgroundSize: false,
}
}