Box Shadows and Text Shadows: Depth and Elevation0%
Styling Links with Pseudo-classes

Box Shadows and Text Shadows: Depth and Elevation

Beginner9 min readUpdated: 2026-09-10
Study Materials

Box Shadows and Text Shadows: Depth and Elevation

Have you ever wondered how cards on modern websites look like they are floating gently above the screen, or how buttons appear to rise up toward you when you hover your mouse over them? 🪄

A computer screen is completely flat (2D). But by using Shadows, web designers create the illusion of physical Depth and 3D Elevation!

In this lesson, you will master:

  1. 1
    The 5 values of the box-shadow formula
  2. 2
    Creating soft, realistic card elevations (resting vs hovering)
  3. 3
    The inset shadow for sunken or pressed effects
  4. 4
    The text-shadow property for glows and cinema titles

The Classroom Sunlight & Shadow Puppet Analogy ☀️

Think of the morning sunlight streaming through your classroom window:

Visual Architecture Blueprint
+-------------------------------------------------------------------------+
|                  THE PHYSICS OF REAL-WORLD SHADOWS                      |
+-------------------------------------------------------------------------+
| 1. HAND RESTING ON THE DESK (Low Elevation):                            |
|    • The shadow is tight, dark, and sharp (Blur: 2px).                  |
|    • The hand feels close to the table.                                 |
|                                                                         |
| 2. HAND LIFTED 1 FOOT IN THE AIR (High Elevation):                      |
|    • The shadow becomes much larger, softer, and diffused (Blur: 20px). |
|    • The hand feels like it is floating high above the table!           |
+-------------------------------------------------------------------------+

The 5 Values of box-shadow

A complete box-shadow declaration contains up to 5 values:

Output
box-shadow: offset-x offset-y blur-radius spread-radius color ;
▲ ▲ ▲ ▲ ▲
│ │ │ │ │
│ │ │ │ └─ Shadow color (use rgba!)
│ │ │ └────────────── Expands footprint (optional)
│ │ └───────────────────────────── Softness / fuzziness
│ └───────────────────────────────────────── Vertical shift (Down/Up)
└──────────────────────────────────────────────────── Horizontal shift (Right/Left)
CSS
.card {
box-shadow: 0px 8px 16px rgba(0, 0, 0, 0.1);
}

Let us break down each parameter:

  1. 1
    offset-x (Horizontal Shift):
  • Positive (5px): Shadow moves to the right.
  • Negative (-5px): Shadow moves to the left.
  • 0px: Shadow is centered directly behind the box.
  1. 1
    offset-y (Vertical Shift):
  • Positive (8px): Shadow moves downwards (standard for overhead light).
  • Negative (-8px): Shadow moves upwards.
  1. 1
    blur-radius (Fuzziness):
  • 0px: Completely sharp, hard-edged shadow.
  • 16px: Soft, natural, diffused blur.
  1. 1
    spread-radius (Optional Size Expansion):
  • Expands the physical footprint of the shadow in all directions before blurring.
  1. 1
    color:
  • Always use semi-transparent rgba()! (e.g., rgba(0, 0, 0, 0.08)). Solid pure black (#000) looks harsh, fake, and dated.

The 3-Tier Modern Card Elevation System

Professional UI designers use a consistent elevation hierarchy to show importance:

CSS
/* Level 1: Flat Resting Card (Sitting on the page) */
.card-level-1 {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
 
/* Level 2: Floating Card (Hover state or active element) */
.card-level-2 {
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
transform: translateY(-4px); /* Moves card slightly up! */
}
 
/* Level 3: Modal Dialog / Pop-up (Floating high above the entire screen) */
.modal-window {
box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
}

The Interactive Hover Lift Effect ⭐

You can combine box-shadow with transform: translateY() to make cards smoothly float up when hovered:

CSS
.interactive-card {
background-color: white;
border-radius: 12px;
padding: 24px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.06);
transition: all 0.3s ease; /* Smooth animation */
}
 
.interactive-card:hover {
transform: translateY(-6px); /* Lifts up by 6px */
box-shadow: 0 16px 24px rgba(0, 0, 0, 0.12); /* Shadow gets deeper & softer */
}

The inset Shadow (Sunken / Pressed Effect)

By adding the keyword inset, the shadow is drawn inside the box instead of outside. This creates a carved-out, sunken effect, perfect for pressed buttons, search inputs, or well containers:

CSS
.sunken-input {
background-color: #f1f5f9;
border: 1px solid #cbd5e1;
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06); /* Carved inside! */
padding: 10px 14px;
border-radius: 6px;
}

text-shadow (Glows & Title Effects)

Just like boxes, text can have its own drop shadow using text-shadow!

text-shadow: offset-x offset-y blur-radius color;

(Notice: text-shadow does NOT have a spread radius).

1. Subtle Title Depth:

CSS
/* Gives white text crisp readability over busy background photos */
.hero-title {
color: white;
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

2. Neon Sci-Fi Glow Effect:

By setting both offset-x and offset-y to 0 and using a bright neon color with blur:

CSS
.neon-text {
color: #38bdf8;
text-shadow: 0 0 12px #0284c7, 0 0 24px #38bdf8;
}

Common Beginner Mistakes (Do's and Don'ts)

What Beginners Do (Don't ❌)What You Should Do Instead (Do ✅)Why?
Using solid black: box-shadow: 5px 5px 0 black;Use rgba(0, 0, 0, 0.08).Solid black shadows look like 1995 clip art. Soft translucent shadows mimic natural sunlight.
Making shadows too dark (rgba(0,0,0,0.8)).Keep alpha between 0.05 and 0.2.Heavy dark shadows make your website look muddy and unrefined.
Forgetting transition when changing shadow on hover.Always add transition: all 0.2s ease;.Without transition, the shadow will abruptly snap instead of smoothly gliding.

Quick Revision Summary

  • Shadows create the visual illusion of 3D depth and elevation on a 2D screen.
  • box-shadow formula: offset-x offset-y blur-radius spread-radius color.
  • Always use rgba(0, 0, 0, 0.08) for realistic, soft shadows.
  • The inset keyword casts shadows inside the container for sunken buttons and search inputs.
  • Combine box-shadow with transform: translateY(-4px) for an interactive hover float effect.
  • text-shadow adds depth to text and creates neon glow effects.

Practice Quiz

Test your understanding with these multiple-choice questions:

1. In the declaration box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);, what does the value 8px represent?

A. Horizontal offset (offset-x) B. Vertical offset (offset-y) C. Blur radius D. Spread radius Answer: B Explanation: In the box-shadow syntax, the first value is offset-x (horizontal) and the second value is offset-y (vertical). 8px pushes the shadow 8 pixels downwards.


2. Which keyword is placed inside a box-shadow declaration to make the shadow appear inside the element instead of outside?

A. inside B. inner C. inset D. internal Answer: C Explanation: The inset keyword changes the shadow from an outer drop shadow to an inner shadow that sits inside the box's borders.


3. Why do professional web designers prefer rgba(0, 0, 0, 0.1) over solid black for card shadows?

A. rgba() compiles faster in the browser B. Translucent shadows blend softly with backgrounds, mimicking natural diffused sunlight C. Solid black is not allowed in modern CSS D. rgba() works without a graphics card Answer: B Explanation: Solid black creates a harsh, cartoonish outline. Low-alpha rgba() mimics real optical physics by letting background colors show through soft shadow edges.


4. What visual effect does text-shadow: 0 0 15px #38bdf8; produce on text?

A. The text is mirrored backwards B. A centered glowing neon halo appears around the letters C. The text is underlined in blue D. The text drops to the bottom of the page Answer: B Explanation: With zero horizontal and vertical offsets, the blur radiates symmetrically in all directions, producing a glowing neon aura.


5. Which parameter is present in box-shadow but completely absent from text-shadow?

A. Blur radius B. Color C. Spread radius D. Vertical offset Answer: C Explanation: text-shadow takes only x-offset, y-offset, blur-radius, and color. It does not support a spread-radius parameter.


Practice Challenge (Try It Yourself)

  1. 1
    Open your code editor and create floating-card.html.
  2. 2
    Build an interactive, floating project card with a smooth elevation hover state:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Floating Card Challenge</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f1f5f9;
padding: 50px 20px;
display: flex;
justify-content: center;
}
 
.course-card {
width: 100%;
max-width: 360px;
background-color: white;
border-radius: 14px;
padding: 28px;
border: 1px solid #e2e8f0;
/* Level 1 Resting Shadow */
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
transition: transform 0.3s ease, box-shadow 0.3s ease;
cursor: pointer;
}
 
/* Level 2 Floating State on Hover */
.course-card:hover {
transform: translateY(-8px); /* Lifts up smoothly */
box-shadow: 0 16px 30px rgba(37, 99, 235, 0.15); /* Soft glowing blue shadow! */
border-color: #93c5fd;
}
 
.tag {
display: inline-block;
background-color: #eff6ff;
color: #2563eb;
font-size: 12px;
font-weight: bold;
padding: 4px 10px;
border-radius: 4px;
margin-bottom: 12px;
}
 
h3 {
color: #0f172a;
margin-bottom: 8px;
}
 
p {
color: #64748b;
line-height: 1.6;
font-size: 14px;
}
</style>
</head>
<body>
<div class="course-card">
<span class="tag">Beginner Course</span>
<h3>CSS for Beginners</h3>
<p>Master styling, selectors, colors, box model, and interactive shadows with real school projects.</p>
</div>
</body>
</html>
  1. 1
    Open the file in your browser and hover your mouse over the card. Feel how alive, responsive, and tactile the floating card elevation feels! 🎯
Next Lesson

Styling Links with Pseudo-classes

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext