Class reference

Background Color - 图1

Usage

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

Background Color - 图2

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.

Background Color - 图3

all

Background Color - 图4

sm

Background Color - 图5

md

Background Color - 图6

lg

Background Color - 图7

xl

Background Color - 图8

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.

Background Color - 图9

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

  1. <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.

Background Color - 图10

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

  1. <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.

Background Color - 图11

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:

Background Color - 图12

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:

Background Color - 图13