OhMyApps
Back to Blog
Tools Design CSS Box Shadow Tutorial

CSS Box Shadow Generator: Design Beautiful Shadows Visually

5 min read By OhMyApps

Getting box shadows right in CSS usually means writing a value, switching to the browser, checking the result, and repeating until it looks decent. A visual generator lets you adjust offset, blur, spread, color, and opacity in real time and copy the final code when you are satisfied.

What Is CSS Box Shadow?

The box-shadow property adds one or more shadow effects to an element. It accepts several values in a specific order:

box-shadow: offset-x offset-y blur-radius spread-radius color;

Offset X and Offset Y

These control where the shadow is positioned relative to the element. Positive X moves the shadow right, positive Y moves it down. Negative values move the shadow left and up.

/* Shadow shifted 4px right and 4px down */
box-shadow: 4px 4px 0 0 rgba(0, 0, 0, 0.25);

Blur Radius

The blur radius controls how soft the shadow edge appears. A value of 0 creates a hard, crisp shadow. Higher values create a more diffused, natural-looking shadow. Most designs use blur values between 8px and 32px.

Spread Radius

Spread expands or contracts the shadow. A positive value makes the shadow larger than the element, while a negative value makes it smaller. Spread is useful for creating tight, close shadows or glow effects.

/* Glow effect using zero offset and large spread */
box-shadow: 0 0 20px 4px rgba(103, 80, 164, 0.3);

Color and Opacity

Shadow colors are typically set using rgba() or hsla() to control opacity independently. Fully opaque shadows look harsh and unnatural. Most well-designed shadows use 10% to 30% opacity for a subtle, realistic appearance.

Common Shadow Patterns

Subtle Elevation

The most common pattern for cards and containers. A small Y offset with moderate blur simulates natural light from above.

box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.1);

Medium Elevation

For elements that need more visual prominence, like hover states on cards or dropdown menus.

box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.15);

Large Elevation

For modals, dialogs, and elements that float above the page.

box-shadow: 0 12px 40px -8px rgba(0, 0, 0, 0.2);

The negative spread (-8px) keeps the shadow from bleeding out too far on the sides while maintaining depth below.

Layered Shadows

Professional designs often stack multiple shadows to create more realistic depth. A small, sharp shadow handles the close contact, while a larger, softer shadow provides the ambient effect.

box-shadow:
  0 1px 3px rgba(0, 0, 0, 0.12),
  0 8px 24px rgba(0, 0, 0, 0.08);

Inset Shadows

Adding the inset keyword places the shadow inside the element, creating a recessed or pressed-in look. This is useful for input fields, progress bars, and toggle switches.

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

How to Use Our Box Shadow Generator

  1. Adjust the offset sliders to position the shadow horizontally and vertically
  2. Set the blur to control how soft or crisp the shadow edge appears
  3. Tweak the spread to expand or contract the shadow size
  4. Pick a color and adjust opacity for the right intensity
  5. Toggle inset if you need an inner shadow
  6. Copy the CSS when you are happy with the result

Tips

  • Start with a small Y offset (2-4px) and moderate blur (8-16px) for a natural look
  • Keep opacity low (10-25%) to avoid heavy, outdated shadow styles
  • Use negative spread to tighten large blur shadows and keep them focused
  • Layer two shadows for a more realistic depth effect
  • Match shadow color to the background rather than always using black

Shadow Design Guidelines

Light Direction

Consistent light direction across your design is important. Most interfaces assume light comes from the top, so shadows should primarily fall downward (positive Y offset). Mixing shadow directions makes a layout feel inconsistent.

Shadow and Brand

Shadows carry subtle design language. Sharp, high-contrast shadows feel bold and graphic. Soft, low-opacity shadows feel modern and minimal. Match your shadow style to the overall design personality.

Performance

Box shadows are rendered by the browser’s compositor and are generally performant. However, very large blur values on many elements can impact rendering on low-end devices. Stick to reasonable values for production use.

Frequently Asked Questions

Can I add multiple shadows to one element? Yes. Separate each shadow with a comma. They render in order, with the first shadow on top. This is how layered shadow effects are built.

What is the difference between blur and spread? Blur softens the shadow edge and expands it outward from the original size. Spread changes the shadow’s size before blurring. A positive spread makes the shadow bigger; a negative spread makes it smaller.

Should I use rgba or hex for shadow color? Use rgba() or hsla() so you can control opacity directly. Hex colors with alpha (like #00000026) also work in modern browsers.

Do box shadows affect layout? No. Box shadows are purely visual and do not affect element size, position, or layout flow. They can overflow their container, though, so you may need overflow: hidden on parent elements.


Try our free CSS Box Shadow Generator to design beautiful shadows visually and copy the code instantly.

Try Ghost Image Hub

The Chrome extension that makes managing your Ghost blog images a breeze.

Learn More