Utilities for controlling an element's background image.
To give an element a linear gradient background, use one of the bg-gradient-{direction}
utilities, in combination with the gradient color stop utilities.
<div class="bg-gradient-to-r from-yellow-400 via-red-500 to-pink-500 ..."></div>
To control the background image of an element at a specific breakpoint, add a {screen}:
prefix to any existing background image utility. For example, use md:bg-gradient-to-r
to apply the bg-gradient-to-r
utility at only medium screen sizes and above.
<div class="bg-gradient-to-l md:bg-gradient-to-r ..."></div>
For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.
By default, Tailwind includes background image utilities for creating linear gradient backgrounds in eight directions.
You can add your own background images by editing the theme.backgroundImage
section of your tailwind.config.js
file:
// tailwind.config.js
module.exports = {
theme: {
extend: {
backgroundImage: {
+ 'hero-pattern': "url('/img/hero-pattern.svg')",
+ 'footer-texture': "url('/img/footer-texture.png')",
}
}
}
}
These don’t just have to be gradients — they can be any background images you need.
These classes will take the form bg-{key}
, so hero-pattern
will become bg-hero-pattern
for example.
By default, only responsive variants are generated for background image utilities.
You can control which variants are generated for the background image utilities by modifying the backgroundImage
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: {
extend: {
// ...
+ backgroundImage: ['hover', 'focus'],
}
}
}
If you don't plan to use the background image utilities in your project, you can disable them entirely by setting the backgroundImage
property to false
in the corePlugins
section of your config file:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ backgroundImage: false,
}
}