Background Color
Class reference
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.
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:
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: