CSS Box Shadow Generator

Elevate your user interface: Design realistic single, multi-layer, and inset CSS box shadows with live interactive sliders, Material Design elevation presets, and instant CSS code export.

HiFi Toolkit

Box Shadow Generator

Create beautiful CSS box shadows with our intuitive generator

Shadow Controls
Live Preview

Box Shadow Preview

CSS Output
Preset Shadows
Soft Shadow
Medium Shadow
Strong Shadow
Inset Shadow
Neumorphism
Colored Shadow

Mastering CSS Box Shadows: The Definitive Guide to Depth & Elevation

In modern user interface design, visual hierarchy and tactile affordance rely heavily on the perception of depth. Since computer monitors and smartphone screens are flat, two-dimensional glass planes, designers leverage directional lighting cues—primarily shadows—to communicate which elements are clickable, which are elevated above the background, and which are recessed into the surface.

The CSS box-shadow property is one of the most versatile styling tools in front-end development. Whether you are crafting delicate cards for a SaaS dashboard, building floating action buttons for mobile applications, or implementing subtle glassmorphic glow effects, mastering shadow geometry separates amateur websites from award-winning digital experiences.

The Anatomy of a CSS Box Shadow Declaration

A standard box shadow declaration can take between two and six values. Understanding each parameter's role ensures complete creative precision:

ParameterSyntax RoleDefault / Acceptable ValuesVisual Impact on Element
Horizontal Offset (X)Mandatory positionLength units (px, em, rem)Positive values push the shadow to the right; negative values push it to the left.
Vertical Offset (Y)Mandatory positionLength units (px, em, rem)Positive values push the shadow downward (simulating overhead light); negative values push it upward.
Blur RadiusOptional softnessPositive length (0px to 100px+)Controls the Gaussian dispersion. A blur of 0px creates a razor-sharp edge; higher values create soft, feathered ambient halos.
Spread RadiusOptional sizingLength units (can be negative!)Expands the footprint of the shadow beyond the element's perimeter (positive) or shrinks it inwards before blurring (negative).
Color & OpacityOptional colorHex, RGB, RGBA, HSLDefines tint and transparency. Professional designers almost exclusively use rgba() to blend naturally into varying backgrounds.
Inset KeywordOptional modeinsetReverses the shadow direction, drawing the shadow inside the element border to produce an etched or sunken look.

Why Multi-Layered Shadows Look 10x More Realistic

In the real world, natural light rarely casts a single, harsh, uniform shadow. Instead, ambient illumination bounces off walls, desks, and ceilings, creating two distinct shadow components simultaneously:

  1. The Direct (Key) Shadow: A tighter, darker shadow cast directly beneath the object caused by the primary overhead light source blocking direct rays.
  2. The Ambient Shadow: A wide, faint, dispersed shadow caused by indirect light bouncing around the room.

When developers use a single harsh shadow like box-shadow: 0 10px 20px #000;, the result looks muddy and dated. Contrast that with a modern multi-layer stack:

/* Professional Multi-Layered Elevation */
box-shadow:
  0 1px 3px rgba(0, 0, 0, 0.08),  /* Sharp key shadow */
  0 8px 24px rgba(0, 0, 0, 0.06); /* Soft ambient shadow */

By combining multiple comma-separated layers, you achieve photographic realism without distracting darkness.

Material Design Elevation System: Levels 1 to 5

Google's Material Design standardizes elevation into structured physical z-axis heights. Here is how to replicate the official Material elevation hierarchy in your projects:

Elevation LevelCSS RuleRecommended UI Components
Level 1 (Low Rest)box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);Flat cards, list items, search inputs, subtle table rows.
Level 2 (Raised)box-shadow: 0 3px 6px rgba(0,0,0,0.15), 0 2px 4px rgba(0,0,0,0.12);Hovered cards, interactive buttons, tooltips, dropdown menus.
Level 3 (Floating)box-shadow: 0 10px 20px rgba(0,0,0,0.15), 0 3px 6px rgba(0,0,0,0.10);Floating Action Buttons (FAB), navigation app bars, notification toasts.
Level 4 (Overlay)box-shadow: 0 14px 28px rgba(0,0,0,0.20), 0 10px 10px rgba(0,0,0,0.12);Modal dialog boxes, bottom sheets, off-canvas drawers.
Level 5 (Top Tier)box-shadow: 0 19px 38px rgba(0,0,0,0.25), 0 15px 12px rgba(0,0,0,0.15);Lightboxes, critical confirmation alerts, dragged drag-and-drop items.

Performance Optimization: Avoiding Scroll Jank and Repaints

While box-shadows are visually striking, excessive or unoptimized shadows can degrade browser frame rates, especially on mobile devices with high-density displays:

  • The Cost of Gaussian Blur: The browser calculates blur by applying a mathematical convolution filter across neighboring pixels. A 50px blur across a 1000px element requires processing millions of pixel calculations every paint cycle.
  • Do Not Animate 'box-shadow' Directly: Transitioning the box-shadow property during hover animations forces the browser to re-rasterize and repaint the element on every frame. Instead, place the hovered shadow on an absolute pseudo-element (::after) with opacity: 0, and animate opacity: 1 on hover. Since opacity runs on the GPU compositor thread, the animation remains locked at a silky 60fps!
  • Negative Spread Radius Trick: If you want a shadow that only falls downwards without peeking out from the left and right flanks of a card, use a positive Y-offset paired with a negative spread radius: box-shadow: 0 15px 10px -5px rgba(0,0,0,0.2);.

Frequently Asked Questions (FAQs)

The syntax 'box-shadow: [inset] <offset-x> <offset-y> <blur-radius> <spread-radius> <color>' consists of: 1) optional 'inset' keyword to cast the shadow inward; 2) horizontal offset (X); 3) vertical offset (Y); 4) blur radius (softness); 5) spread radius (expansion or contraction of the shadow footprint); and 6) color (typically RGBA or HSLA for opacity).

Blur radius controls the Gaussian dispersion of the shadow edge—a blur of 0px creates a razor-sharp silhouette, while 20px creates a soft, ambient dispersion. Spread radius expands or contracts the underlying shape of the shadow before blur is applied—positive values make the shadow larger than the element, while negative values shrink it.

Natural sunlight creates layered ambient and direct shadows. In CSS, you can separate multiple shadow declarations with commas: 'box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 8px 24px rgba(0,0,0,0.08);'. Combining a tight, darker key shadow with a broad, soft ambient shadow produces lifelike 3D depth without muddy black halos.

Neumorphism simulates extruded plastic surfaces where an element appears to rise seamlessly out of the background. It is achieved by placing an element on an off-white or soft-gray background and applying two opposing shadows: a light shadow (e.g. -6px -6px 16px rgba(255,255,255,0.8)) in the top-left and a dark shadow (e.g. 6px 6px 16px rgba(0,0,0,0.15)) in the bottom-right.

No. The box-shadow property is purely visual and exists outside the standard CSS box model. It does not alter element width, height, margins, or surrounding document flow, meaning you can toggle shadow effects on hover without triggering layout reflow.

Yes. High blur radii (e.g., > 50px) combined with massive spread values force the browser's rasterizer to calculate expensive Gaussian blur filters on the CPU/GPU for every frame during page scrolling. To optimize performance, avoid animating large box-shadows directly; instead, animate the 'opacity' of a pseudo-element ('::after') carrying the target shadow.

Prepend the 'inset' keyword to the shadow rule: 'box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);'. This casts the shadow inside the element's border box, creating a pressed, sunken, or carved appearance widely used in form input fields, wells, and depressed toggle buttons.

Tailwind provides pre-configured shadow utilities: 'shadow-sm', 'shadow', 'shadow-md', 'shadow-lg', 'shadow-xl', and 'shadow-2xl'. For custom multi-layer shadows, you can use arbitrary value syntax: 'shadow-[0_10px_30px_rgba(0,0,0,0.15)]'.