Tailwind CSS on GitHub

Background Image

Utilities for controlling an element's background image.

Default class reference

bg-nonebackground-image: none;
bg-gradient-to-tbackground-image: linear-gradient(to top, var(--tw-gradient-stops));
bg-gradient-to-trbackground-image: linear-gradient(to top right, var(--tw-gradient-stops));
bg-gradient-to-rbackground-image: linear-gradient(to right, var(--tw-gradient-stops));
bg-gradient-to-brbackground-image: linear-gradient(to bottom right, var(--tw-gradient-stops));
bg-gradient-to-bbackground-image: linear-gradient(to bottom, var(--tw-gradient-stops));
bg-gradient-to-blbackground-image: linear-gradient(to bottom left, var(--tw-gradient-stops));
bg-gradient-to-lbackground-image: linear-gradient(to left, var(--tw-gradient-stops));
bg-gradient-to-tlbackground-image: linear-gradient(to top left, var(--tw-gradient-stops));

Linear gradients

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.


Background Images

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: theme => ({
+         '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,