LEGACY Tailwind CSS v3-era example, archived unchanged. Kept for reference only — it uses the v3 Play CDN and JS config, both removed in v4. Current documentation →

Tailwind CSS Backgrounds & Shadows

Create depth, dimension, and visual interest in your designs using Tailwind's powerful background and shadow utilities

What are Backgrounds & Shadows?

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.

Key Concept

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.

Material Design Principles

  • • Higher shadows = higher elevation
  • • Interactive elements should use shadows to indicate their state
  • • Consistent background & shadow usage creates a cohesive user experience

Background Properties

  • •
    Color & Gradients

    Solid colors and multi-color gradients

  • •
    Images & Positioning

    Control the size, position, and repeat behavior

  • •
    Attachment

    Fixed, local, or scrolling behavior

  • •
    Blend Modes

    Control how backgrounds blend with content

Shadow Properties

  • •
    Size & Intensity

    From subtle to dramatic elevation effects

  • •
    Direction

    Outer or inner shadows

  • •
    Color

    Custom colors and opacity control

  • •
    Interactive States

    Shadows that respond to user interactions

Basic

Layered

Inner Shadow

Image

Practical Examples

Background Images

Essential

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

Background Image Properties

Size
  • bg-auto
  • bg-cover
  • bg-contain
Position
  • bg-bottom
  • bg-center
  • bg-left
  • bg-right
  • bg-top
Repeat
  • bg-repeat
  • bg-no-repeat
  • bg-repeat-x
  • bg-repeat-y
<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>

Gradient Backgrounds

Popular

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.

Direction Variants

bg-gradient-to-r
bg-gradient-to-br
bg-gradient-to-b

Multi-Color Gradients

from-indigo-500 to-purple-500
from-indigo-500 via-purple-500 to-pink-500
from-yellow-400 via-red-500 to-pink-500

Gradient Applications

Page Header
Create eye-catching headers and hero sections
Attention-grabbing buttons & CTAs

Gradient Text

Create eye-catching text with bg-clip-text
<!-- 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>

Shadow Effects

UI Essential

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 me
shadow-sm

Shadow MD

Hover me
shadow-md

Shadow XL

Hover me
shadow-xl

Shadow Variations

Inner Shadows

Inset shadow effect

shadow-inner
Colored Shadows
shadow-blue-500/50
shadow-pink-500/50

Interactive Shadow Effects

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

Colored Shadows

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

Advanced

Mix blend modes determine how elements blend with layers below them. They can create unique visual effects when colors and images overlap.

Multiply

mix-blend-multiply

Screen

mix-blend-screen

Overlay

mix-blend-overlay

Difference

mix-blend-difference

Color Dodge

mix-blend-color-dodge

Common Blend Mode Applications

Photo Effects
City photo

Using mix-blend-overlay to create color effects on photos

Text Interactions

CREATIVE TEXT

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 Cases & Best Practices

Recommended

Cards & UI Components

Use shadows to create hierarchy and indicate interactivity, with stronger shadows for more elevated elements.

Interactive Card

Combines shadow with hover transition

Accented Card

Combines shadow with colored border

Buttons & Interactive Elements

Gradient backgrounds and shadows can make buttons more engaging and provide clearer feedback on interaction.

Page Sections & Layouts

Header Section

Use background gradients for visual distinction between page sections

Sidebar
Content

Visual Effects & Graphics

Creative Overlays

Performance Considerations

  • Box-shadows can affect performance, especially on elements that animate or frequently repaint
  • Gradient backgrounds are generally more performant than complex background images
  • Avoid too many mix-blend-mode overlays in the same view for better rendering performance

Quick Reference Guide

Background Utilities

Background Size
bg-auto
bg-cover
bg-contain
Background Position
bg-bottom
bg-center
bg-left
bg-right
bg-top
bg-left-top
bg-right-top
bg-left-bottom
bg-right-bottom
Background Attachment
bg-fixed
bg-local
bg-scroll

Shadow Utilities

Shadow Sizes
shadow-sm
shadow
shadow-md
shadow-lg
shadow-xl
shadow-2xl
shadow-inner
shadow-none
Mix Blend Modes
mix-blend-normal
mix-blend-multiply
mix-blend-screen
mix-blend-overlay
mix-blend-darken
mix-blend-lighten
mix-blend-color-dodge
mix-blend-color-burn
mix-blend-hard-light
mix-blend-soft-light
mix-blend-difference
mix-blend-exclusion
mix-blend-hue
mix-blend-saturation
mix-blend-color
mix-blend-luminosity
Tailwind Config Example
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)',
      }
    }
  }
}

Complete Reference Guide

Comprehensive examples of Tailwind CSS background and shadow utilities

Background Property Showcase

Background Size

Original Image
Original image

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
When to use each option:
  • 1 bg-auto: Use when the original image size is important or when tiling
  • 2 bg-cover: Hero images, cards, or when the image must fill its container completely
  • 3 bg-contain: Icons, logos, or when the entire image must be visible

Advanced Gradient Techniques

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

Practical Gradient Applications

Call-to-action button with gradient

Notification

New features available!

Alert/notification with gradient background

Premium

Gradient text using bg-clip-text

Advanced Shadow Techniques

Interactive Elements with Shadows

Interactive Card

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 Shadows with Other Effects

Left Border Accent

Combining shadow with a colored border accent

shadow-md border-l-4 border-blue-500
Gradient Border

Gradient border illusion using padding

bg with gradient, inner div with bg-white
Nested Shadows

Outer shadow + inner shadow effect

Outer: shadow-md, Inner: shadow-inner

Real-World UI Components

Modal Dialog

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

Mix Blend Mode Playground

Experiment with different mix blend modes to create unique visual effects:

Layered Gradients

Using multiple blend modes

mix-blend-multiply & mix-blend-screen

BLEND

mix-blend-overlay (text) & mix-blend-multiply (overlay)

Quick Reference

Background Size

bg-auto
bg-cover     // Scale to cover entire container
bg-contain   // Scale to fit within container

Background Position

bg-bottom       bg-center       bg-left
bg-left-bottom  bg-left-top     bg-right
bg-right-bottom bg-right-top    bg-top

Background Attachment

bg-fixed    // Fixed relative to viewport
bg-local    // Scrolls with content
bg-scroll   // Scrolls with element

Shadow Sizes

shadow-sm   // Smallest shadow
shadow      // Default shadow
shadow-md   shadow-lg   shadow-xl   shadow-2xl
shadow-inner // Inset shadow
shadow-none // No shadow

Colored Shadows

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

Summary & Best Practices

Key takeaways for using backgrounds and shadows effectively

Backgrounds Best Practices

  • Choose bg-cover for most hero images and card backgrounds
  • Use bg-contain for logos and icons when the entire image must be visible
  • Consider gradients instead of images for better performance and responsive design
  • Use bg-fixed sparingly as it can cause performance issues on mobile devices

Shadows Best Practices

  • Use shadow intensity to indicate elevation in your interface hierarchy
  • Apply shadow-lg or shadow-xl for floating elements like modals and popovers
  • Combine shadows with hover states to create interactive elements
  • Use colored shadows to match your brand colors or create special effects

Try it Yourself

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>