Background Color

    Utilities for controlling an element’s background color.

    Show all classes

    Control the background color of an element using the utilities.

    Changing the opacity

    Control the opacity of an element’s background color using the color opacity modifier.

    Background Color - 图2

    1. <button class="bg-sky-500/100 ..."></button>
    2. <button class="bg-sky-500/75 ..."></button>
    3. <button class="bg-sky-500/50 ..."></button>

    Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:bg-cyan-600 to only apply the bg-cyan-600 utility on hover.

    Try hovering over the button to see the background color change

    Background Color - 图4

    1. <button class="bg-cyan-500 hover:bg-cyan-600 ...">Subscribe</button>

    For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

    Breakpoints and media queries

    You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:bg-green-500 to apply the utility at only medium screen sizes and above.


    By default, Tailwind makes the entire default color palette available as background colors. You can by editing theme.colors or theme.extend.colors in your tailwind.config.js file.

    tailwind.config.js

    1. module.exports = {
    2. extend: {
    3. colors: {
    4. },
    5. }
    6. }
    7. }

    Alternatively, you can customize just your background colors by editing theme.backgroundColor or theme.extend.backgroundColor in your tailwind.config.js file.

    Learn more about customizing the default theme in the theme customization documentation.

    Arbitrary values

    If you need to use a one-off value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

    Learn more about arbitrary value support in the arbitrary values documentation.