Create depth, dimension, and visual interest in your designs using Tailwind's powerful background and shadow utilities
Backgrounds and shadows are fundamental visual elements that create depth, establish hierarchy, and enhance the aesthetics of your web designs. In Tailwind CSS, these properties are implemented through intuitive utility classes that allow you to quickly apply sophisticated visual effects.
Backgrounds can be solid colors, gradients, or images, and can be customized with properties like size, position, and attachment. They set the visual foundation for your elements and help establish your brand identity.
Shadows create the illusion of elevation and depth, helping users understand the relationship between different interface elements. Shadows can vary in size, intensity, color, and can be applied to the outside or inside of elements.
Backgrounds and shadows work together to create a visual language in your UI. Shadows convey elevation (how far an element is from the surface), while backgrounds define the surface itself.
Solid colors and multi-color gradients
Control the size, position, and repeat behavior
Fixed, local, or scrolling behavior
Control how backgrounds blend with content
From subtle to dramatic elevation effects
Outer or inner shadows
Custom colors and opacity control
Shadows that respond to user interactions
Basic
Layered
Inner Shadow
Image
Background images in Tailwind CSS come with a variety of utilities to control their size, position, and behavior.
bg-cover bg-no-repeat bg-center
Hover me
Hover Overlay
bg-cover + overlay with opacity transition
Hover me
<div
class="h-64 bg-cover bg-center bg-no-repeat rounded-lg"
style="background-image: url('/path/to/image.jpg')"
>
<!-- Content overlaid on the background image -->
<div class="p-6 text-white">
<h2 class="text-2xl font-bold">Hero Title</h2>
<p>Supporting text goes here</p>
</div>
</div>
Tailwind CSS makes it easy to create beautiful gradient backgrounds with simple utility classes. Gradients can add depth, visual interest, and guide the user's attention.
bg-gradient-to-r
bg-gradient-to-br
bg-gradient-to-b
from-indigo-500 to-purple-500
from-indigo-500 via-purple-500 to-pink-500
from-yellow-400 via-red-500 to-pink-500
<!-- Basic gradient -->
<div class="bg-gradient-to-r from-cyan-500 to-blue-500"></div>
<!-- Three-color gradient -->
<div class="bg-gradient-to-r from-indigo-500 via-purple-500 to-pink-500"></div>
<!-- Gradient text -->
<h2 class="text-transparent bg-clip-text bg-gradient-to-r from-purple-600 to-pink-600">
Gradient Text
</h2>
Shadows in Tailwind CSS help create the illusion of elevation and depth. Different shadow sizes convey different levels of elevation from the surface.
Shadow SM
Hover meshadow-sm
Shadow MD
Hover meshadow-md
Shadow XL
Hover meshadow-xl
Inset shadow effect
shadow-inner
shadow-blue-500/50
shadow-pink-500/50
Group Hover
Using group utilities
Colored Shadow
Matching brand colors
<!-- Basic shadow with hover effect -->
<div class="bg-white rounded-lg shadow-md hover:shadow-xl transition-all">
Content here
</div>
<!-- Colored shadow -->
<div class="bg-white rounded-lg shadow-lg shadow-blue-500/50">
Content with blue shadow
</div>
<!-- Interactive card with group hover -->
<div class="group">
<div class="bg-white rounded-lg shadow-md
group-hover:shadow-xl
group-hover:-translate-y-1
transition-all">
Card content here
</div>
</div>
Shadow LG
shadow-lg
Shadow XL
shadow-xl
Shadow 2XL
shadow-2xl
Blue Shadow (50% opacity)
shadow-xl shadow-blue-500/50
Red Shadow (100% opacity)
shadow-xl shadow-red-500/100
Inner Shadow
shadow-inner
Creates the appearance of being inset or depressed
Mix blend modes determine how elements blend with layers below them. They can create unique visual effects when colors and images overlap.
mix-blend-multiply
mix-blend-screen
mix-blend-overlay
Difference
mix-blend-difference
Color Dodge
mix-blend-color-dodge
Using mix-blend-overlay to create color effects on photos
Using mix-blend-difference for creative text effects
<!-- Basic mix-blend effect -->
<div class="relative">
<div class="bg-blue-500"></div>
<div class="absolute inset-0 bg-red-500 mix-blend-multiply"></div>
</div>
<!-- Text with blend mode -->
<div class="bg-gradient-to-r from-blue-500 to-purple-500">
<h2 class="text-white mix-blend-difference">Blended Text</h2>
</div>
Use shadows to create hierarchy and indicate interactivity, with stronger shadows for more elevated elements.
Combines shadow with hover transition
Combines shadow with colored border
Gradient backgrounds and shadows can make buttons more engaging and provide clearer feedback on interaction.
Use background gradients for visual distinction between page sections
Creative Overlays
module.exports = {
theme: {
extend: {
backgroundImage: {
'hero-pattern': "url('/img/hero-pattern.svg')",
'footer-texture': "url('/img/footer-texture.png')",
},
boxShadow: {
'custom': '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
'glow': '0 0 15px rgba(79, 70, 229, 0.5)',
}
}
}
}
Comprehensive examples of Tailwind CSS background and shadow utilities
Original size, may tile or not fill container
bg-auto
Hover to see details
Covers entire container, maintains aspect ratio
bg-cover
Hover to see details
Fits within container, maintains aspect ratio
bg-contain
Hover to see details
bg-gradient-to-tr from-yellow-400 via-red-500 to-pink-500
Top-left to bottom-right with three colors
bg-gradient-to-bl from-green-300 via-blue-500 to-purple-600
Top-right to bottom-left with three colors
Call-to-action button with gradient
Notification
New features available!
Alert/notification with gradient background
Gradient text using bg-clip-text
Card with shadow, border and text color transitions
Hover over this card to see all effects
Click on the input field to see focus effect
Combining shadow with a colored border accent
shadow-md border-l-4 border-blue-500
Gradient border illusion using padding
bg with gradient, inner div with bg-white
Outer shadow + inner shadow effect
Outer: shadow-md, Inner: shadow-inner
Strong shadows help modals stand out from the background, creating a clear visual hierarchy.
Modal with shadow-2xl to create significant elevation
Success!
Your changes have been saved.
Toast notification with shadow and left border accent
Experiment with different mix blend modes to create unique visual effects:
Using multiple blend modes
mix-blend-multiply & mix-blend-screen
mix-blend-overlay (text) & mix-blend-multiply (overlay)
bg-auto bg-cover // Scale to cover entire container bg-contain // Scale to fit within container
bg-bottom bg-center bg-left bg-left-bottom bg-left-top bg-right bg-right-bottom bg-right-top bg-top
bg-fixed // Fixed relative to viewport bg-local // Scrolls with content bg-scroll // Scrolls with element
shadow-sm // Smallest shadow shadow // Default shadow shadow-md shadow-lg shadow-xl shadow-2xl shadow-inner // Inset shadow shadow-none // No shadow
shadow-red-500/50 // Red shadow at 50% opacity shadow-blue-500/75 // Blue shadow at 75% opacity shadow-green-500/100 // Green shadow at 100% opacity
Key takeaways for using backgrounds and shadows effectively
Experiment with these code snippets in your own projects:
// Hero image with overlay text
<div class="relative">
<div
class="h-64 bg-cover bg-center"
style="background-image: url('image.jpg')">
<div class="absolute inset-0 bg-black opacity-50"></div>
<div class="relative z-10 p-6 text-white">
<h2 class="text-2xl font-bold">Title Here</h2>
<p>Description text</p>
</div>
</div>
</div>
// Interactive card with hover effects
<div class="group">
<div class="p-6 bg-white rounded-lg shadow-md
group-hover:shadow-xl
transition-all duration-300">
<h3 class="font-bold text-gray-800
group-hover:text-blue-500">Card Title</h3>
<p class="text-gray-600 mt-2">Card content</p>
<button class="mt-4 px-4 py-2 bg-gray-100 rounded
group-hover:bg-blue-500
group-hover:text-white">
Learn More
</button>
</div>
</div>