Background colors are probably one of the first things you'll use when starting with Tailwind CSS.
They're everywhere in web design. Buttons, cards, hero sections, navbars, footers... you name it. Getting comfortable with how background colors work in Tailwind will save you tons of time and make your styling workflow much smoother.
The good news is that Tailwind makes it super simple to apply background colors while giving you enough flexibility to handle any design requirement. Let me walk you through everything you need to know.
When you install Tailwind CSS, you get an incredibly well-designed color palette right out of the gate. No need to spend hours picking colors or creating your own system.
Here's what you're working with: 18 different color families (red, blue, green, purple, and more), plus neutral tones like gray, slate, zinc, and stone.
Each color family has 11 shades numbered from 50 to 950. The lower numbers (like 50, 100, 200) are lighter, while higher numbers (800, 900, 950) are darker. The middle values like 500 or 600 are your standard, vibrant colors.
So if you want a light blue background, you'd use bg-blue-100. Want something darker? Try bg-blue-800.
<div class="bg-blue-50 p-4">Very light blue</div>
<div class="bg-blue-500 p-4">Standard blue</div>
<div class="bg-blue-900 p-4">Dark blue</div>
You also get some special values like bg-white, bg-black, bg-transparent, and bg-current (which inherits the text color). These come in handy more often than you'd think.
The numbering system is consistent across all colors, so once you learn that 500 is the standard shade and 100 is light, you can apply that knowledge to any color. bg-red-500, bg-green-500, bg-purple-500 all follow the same pattern.
Sometimes you need a background color that's semi-transparent. Maybe you're building an overlay, a glass-morphism effect, or just want a subtle background that doesn't completely hide what's behind it.
Tailwind used to have separate opacity utilities, but now there's a much cleaner way: the slash syntax.
Just add a forward slash and a number after your color class. The number represents the opacity percentage.
For example, bg-black/50 gives you a black background at 50% opacity. bg-blue-500/75 is your standard blue at 75% opacity. Simple, right?
<div class="relative h-64 bg-[url('https://images.pexels.com/photos/1261728/pexels-photo-1261728.jpeg')] bg-cover bg-center">
<div class="absolute inset-0 bg-black/60 flex items-center justify-center">
<h2 class="text-white text-3xl font-bold">Hero Section</h2>
</div>
</div>
The opacity value can be anything from 0 to 100. You can even use values like bg-blue-500/25 for 25% opacity or bg-red-600/90 for 90% opacity.
This is super useful for things like:
One thing I love about this approach is how readable it is. When you see bg-blue-500/50 in your markup, you immediately know it's blue at half opacity. No need to hunt down what bg-opacity-50 does or remember which class it's paired with.
The default color palette is great, but sometimes you need a specific brand color or a one-off custom shade that's not in Tailwind's defaults.
You've got two solid options here.
The first one is arbitrary values using square brackets. Just drop your color code right into the class like this: bg-[#50d71e].
You can use hex codes, RGB, HSL, whatever CSS accepts. bg-[rgb(80,215,30)] or bg-[hsl(100,75%,48%)] both work perfectly fine.
<button class="bg-[#ff6b6b] hover:bg-[#ee5a52] text-white px-6 py-3 rounded-lg">
Custom Brand Button
</button>
<div class="bg-[rgb(74,222,128)] p-6 rounded-lg">
RGB Color Background
</div>
The second option is using CSS custom properties (variables). If you define a color in your CSS like --brand-primary, you can reference it with bg-(--brand-primary).
Tailwind automatically wraps it in the var() function for you, so you don't have to write bg-[var(--brand-primary)]. Just the simpler bg-(--brand-primary) works.
This is perfect when you're working with a design system or need to reference colors that might change based on themes or user preferences.
I usually reach for arbitrary values when I need a quick one-off color. For colors I'll reuse throughout the project, CSS custom properties or extending the theme makes more sense.
Static backgrounds are fine, but modern web design is all about interactivity and responsive layouts. Tailwind makes it dead simple to change background colors based on user interaction or screen size.
Want a button that changes color when you hover over it? Just prefix the background class with hover:.
<button class="bg-blue-500 hover:bg-blue-600 text-white px-6 py-3 rounded-lg">
Hover me
</button>
<button class="bg-green-500 hover:bg-green-700 focus:bg-green-800 active:bg-green-900 text-white px-6 py-3 rounded-lg">
Multiple states
</button>
You can also combine multiple state variants. focus:bg-green-700 for when the button has focus, active:bg-green-800 for when it's being clicked.
Responsive backgrounds are just as easy. Use breakpoint prefixes like md:, lg:, or xl:.
<div class="bg-red-100 md:bg-blue-100 lg:bg-green-100 p-8 rounded-lg">
<p class="text-gray-800 font-medium">
This background changes color at different breakpoints
</p>
</div>
The element will be red on mobile (bg-red-100), blue on tablets and up (md:bg-blue-100), and green on larger screens (lg:bg-green-100).
You can even combine state and responsive modifiers: md:hover:bg-purple-600 only applies the hover effect on medium screens and larger. Pretty powerful stuff.
Let me show you some real-world scenarios where background colors really shine.
First up, status indicators. These are super common in dashboards and admin panels:
<div class="flex gap-3">
<span class="bg-green-100 text-green-800 px-3 py-1 rounded-full text-sm font-medium">Active</span>
<span class="bg-yellow-100 text-yellow-800 px-3 py-1 rounded-full text-sm font-medium">Pending</span>
<span class="bg-red-100 text-red-800 px-3 py-1 rounded-full text-sm font-medium">Inactive</span>
</div>
Card backgrounds are another common use case. Light backgrounds help separate content and create visual hierarchy:
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="bg-white p-6 rounded-lg shadow-md">
<h3 class="text-lg font-bold text-gray-800 mb-2">Basic Plan</h3>
<p class="text-gray-600">Perfect for individuals</p>
</div>
<div class="bg-blue-50 p-6 rounded-lg shadow-md border-2 border-blue-500">
<h3 class="text-lg font-bold text-blue-900 mb-2">Pro Plan</h3>
<p class="text-blue-700">Most popular choice</p>
</div>
<div class="bg-white p-6 rounded-lg shadow-md">
<h3 class="text-lg font-bold text-gray-800 mb-2">Enterprise</h3>
<p class="text-gray-600">For large teams</p>
</div>
</div>
Notice how the Pro plan uses a colored background to stand out? That's a simple but effective design pattern.
Here's one more: alert boxes with different severity levels.
<div class="space-y-3">
<div class="bg-blue-50 border-l-4 border-blue-500 p-4">
<p class="text-blue-700 font-medium">Info: Your profile has been updated</p>
</div>
<div class="bg-green-50 border-l-4 border-green-500 p-4">
<p class="text-green-700 font-medium">Success: Payment processed successfully</p>
</div>
<div class="bg-red-50 border-l-4 border-red-500 p-4">
<p class="text-red-700 font-medium">Error: Please check your input</p>
</div>
</div>
The light background colors (like bg-blue-50, bg-green-50) combined with darker text colors create clear, accessible alerts that grab attention without being overwhelming.
That's pretty much everything you need to know about background colors in Tailwind CSS. You've got a solid color palette, easy opacity control, custom color options, and powerful state/responsive modifiers.
Start with the defaults, learn the numbering system, and don't be afraid to use arbitrary values when you need them. The more you use these utilities, the faster your workflow gets.
Hope this helps you build better interfaces with Tailwind!
Get notified when we add new templates, components, and more!
WindyBase is a weekly curated Tailwind CSS template and tool directory built for the modern developer.
© 2025 WindyBase. All rights reserved.