UCSSR

CSS Box Shadow Generator

Create and visualize CSS box shadow effects with a real-time preview and customizable options.

Shadow Layers

Shadow
5px 5px 10px 0px
5px
5px
10px
0px
20%
box-shadow
box-shadow: 5px 5px 10px 0px rgba(0, 0, 0, 0.2);

Box Shadow Guide

The CSS box-shadow property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radius, and color.

Box shadows are essential for creating depth and hierarchy in modern web design. They help establish visual relationships between elements and can guide users through your interface by creating subtle visual cues about element importance and interactivity.

Interactive Shadow Builder

Live Preview
↑ This box updates in real-time with your shadow settings
5px
X Offset
5px
Y Offset
10px
Blur
0px
Spread

Anatomy of a Box Shadow

X-offset
Y-offset
Spread
Blur
box-shadow: [inset?] x-offset y-offset blur-radius spread-radius color;
inset
If present, the shadow is drawn inside the element
x-offset
Horizontal distance (positive = right, negative = left)
y-offset
Vertical distance (positive = down, negative = up)
blur-radius
The larger the value, the bigger the blur (default 0)
spread-radius
Positive values increase size, negative decrease (default 0)
color
Color of the shadow (supports rgba for opacity)

Common Use Cases

Box shadows serve different purposes in UI design. From subtle depth indicators to interactive feedback, here are some common patterns and when to use them. The key is to use shadows purposefully to enhance usability and visual hierarchy.

Elevation Shadow
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);

Perfect for cards and elevated surfaces

Inset Shadow
box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.1);

Creates a pressed or sunken effect

Hover Effect
transition: box-shadow 0.3s ease;

Interactive hover states

Design Principles

Creating effective shadows is about more than just adding depth. It's about creating a cohesive visual language that enhances your user interface and improves user experience. Here are key principles to follow when working with box shadows, along with practical examples and guidelines.

1. Natural Light Direction

Shadows should follow a consistent light source direction, typically from above. This creates a natural, intuitive feel that users subconsciously understand. Consider these aspects:

  • • Light typically comes from above (0° to 45° angle)
  • • Shadows should fall below and slightly to one side
  • • Maintain consistency across your interface
Light Source

2. Multiple Shadows

Combining multiple shadows can create more realistic and nuanced depth effects. This technique is particularly effective for creating sophisticated elevation hierarchies:

  • • Ambient shadow (large, soft spread)
  • • Direct shadow (smaller, sharper)
  • • Optional inner shadow for depth
Hover me

3. Subtle is Better

Shadows should enhance the user interface without drawing attention to themselves. Follow these guidelines for subtle, effective shadows:

  • • Use low opacity (0.1-0.2)
  • • Keep blur radius moderate
  • • Avoid harsh, dark shadows
Subtle
opacity: 0.1
Harsh
opacity: 0.5

4. Interactive States

Use shadows to provide visual feedback for interactive elements. This creates a more engaging and responsive interface:

  • • Default state: subtle shadow
  • • Hover: increased elevation
  • • Active/Pressed: reduced elevation

5. Elevation Hierarchy

Use shadow intensity to establish a clear visual hierarchy. Higher elevation suggests greater importance or interaction priority:

Base Level
Cards, containers
Medium Level
Dropdowns, popovers
High Level
Modals, dialogs

6. Contextual Shadows

Adapt shadow styles based on the context and purpose of the element:

Inset Shadow
Form inputs, pressed states
Ambient Shadow
Cards, containers
Directional Shadow
Floating elements

Shadow Scale System

Implement a consistent shadow scale system to maintain visual harmony across your interface. Each level serves a specific purpose and should be used consistently:

Level 1
Low emphasis
Cards, sections
Level 2
Medium emphasis
Navigation, toolbars
Level 3
High emphasis
Modals, dialogs

Performance Considerations

While box shadows are powerful design tools, they can impact performance if not used carefully. Understanding these considerations will help you create efficient, performant interfaces without sacrificing visual quality.

What to Avoid

⚠️

Large blur-radius values (>20px) can impact rendering performance

⚠️

Multiple complex shadows

⚠️

Animating box-shadow directly

Best Practices

Use transform for animations

Optimize with will-change

Keep shadows simple and subtle

Quick Tips

Different UI elements require different types of shadows to effectively communicate their purpose and hierarchy. Here are some tried-and-tested shadow configurations for common UI elements.

📇

For Cards

box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);

Light elevation for card elements

🔽

For Dropdowns

box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);

Medium elevation for floating elements

🪟

For Modals

box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

Heavy elevation for modal dialogs

✏️

For Input Fields

box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.06);

Subtle inset shadow for form inputs