Tailwind CSS v1.0 is here! Learn more →

Background Color

Utilities for controlling an element's background color.

Class reference

Class
.bg-transparent
.bg-black
.bg-grey-darkest
.bg-grey-darker
.bg-grey-dark
.bg-grey
.bg-grey-light
.bg-grey-lighter
.bg-grey-lightest
.bg-white
.bg-red-darkest
.bg-red-darker
.bg-red-dark
.bg-red
.bg-red-light
.bg-red-lighter
.bg-red-lightest
.bg-orange-darkest
.bg-orange-darker
.bg-orange-dark
.bg-orange
.bg-orange-light
.bg-orange-lighter
.bg-orange-lightest
.bg-yellow-darkest
.bg-yellow-darker
.bg-yellow-dark
.bg-yellow
.bg-yellow-light
.bg-yellow-lighter
.bg-yellow-lightest
.bg-green-darkest
.bg-green-darker
.bg-green-dark
.bg-green
.bg-green-light
.bg-green-lighter
.bg-green-lightest
.bg-teal-darkest
.bg-teal-darker
.bg-teal-dark
.bg-teal
.bg-teal-light
.bg-teal-lighter
.bg-teal-lightest
.bg-blue-darkest
.bg-blue-darker
.bg-blue-dark
.bg-blue
.bg-blue-light
.bg-blue-lighter
.bg-blue-lightest
.bg-indigo-darkest
.bg-indigo-darker
.bg-indigo-dark
.bg-indigo
.bg-indigo-light
.bg-indigo-lighter
.bg-indigo-lightest
.bg-purple-darkest
.bg-purple-darker
.bg-purple-dark
.bg-purple
.bg-purple-light
.bg-purple-lighter
.bg-purple-lightest
.bg-pink-darkest
.bg-pink-darker
.bg-pink-dark
.bg-pink
.bg-pink-light
.bg-pink-lighter
.bg-pink-lightest

Usage

Control the background color of an element using the .bg-{color} utilities.

<button class="bg-blue ...">Button</button>

Responsive

To control the background color of an element at a specific breakpoint, add a {screen}: prefix to any existing background color utility. For example, use md:bg-green to apply the bg-green utility at only medium screen sizes and above.

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

Hover

To control the background color of an element on hover, add the hover: prefix to any existing background color utility. For example, use hover:bg-blue to apply the bg-blue utility on hover.

<button class="bg-blue hover:bg-blue-dark ...">
  Hover me
</button>

Hover utilities can also be combined with responsive utilities by adding the responsive {screen}: prefix before the hover: prefix.

<button class="... md:bg-blue md:hover:bg-blue-dark ...">Button</button>

Focus

To control the background color of an element on focus, add the focus: prefix to any existing background color utility. For example, use focus:bg-blue to apply the bg-blue utility on focus.

<input class="bg-grey-lighter focus:bg-white ...">

Focus utilities can also be combined with responsive utilities by adding the responsive {screen}: prefix before the focus: prefix.

<input class="... md:bg-grey-lighter md:focus:bg-white ...">

Customizing

Background Colors

By default Tailwind makes the entire default color palette available as background colors.

You can customize your color palette by editing the colors variable in your Tailwind config file, or customize just your background colors using the backgroundColors section of your Tailwind config.

{
// ...
backgroundColors: {
-   ...colors,
+   'primary': '#3490dc',
+   'secondary': '#ffed4a',
+   'danger': '#e3342f',
}
}

Responsive and State Variants

By default, only responsive, hover and focus variants are generated for background color utilities.

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

For example, this config will also generate variants:

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

Disabling

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

{
// ...
modules: {
    // ...
-   backgroundColors: ['responsive', 'hover', 'focus'],
+   backgroundColors: false,
}
}