CSS Box Shadows and Gradients: A Visual Design Guide

Dev Tools March 8, 2026 9 min read

Two CSS properties can transform a flat, boring design into something that feels polished and professional: box-shadow and gradients. Whether you're building a landing page, designing cards, or styling buttons, mastering these properties gives you powerful visual tools without any images or JavaScript.

CSS Box Shadows

Basic Syntax

The box-shadow property takes up to 6 values:

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

Common Shadow Patterns

Subtle elevation (cards):

box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
Subtle

Medium elevation (dropdowns, modals):

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

Heavy elevation (floating elements):

box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
Heavy

Multiple Shadows

You can stack multiple shadows separated by commas. This creates more realistic, layered depth:

box-shadow:
  0 1px 2px rgba(0, 0, 0, 0.07),
  0 4px 8px rgba(0, 0, 0, 0.07),
  0 16px 32px rgba(0, 0, 0, 0.07);

Performance Tips

CSS Gradients

Linear Gradients

The most common type. Colors blend along a straight line:

background: linear-gradient(135deg, #667eea, #764ba2);
Linear

The angle determines direction: 0deg = bottom to top, 90deg = left to right, 180deg = top to bottom. You can also use keywords like to right, to bottom left, etc.

Radial Gradients

Colors radiate outward from a center point:

background: radial-gradient(circle at 30% 40%, #f093fb, #f5576c);
Radial

Conic Gradients

Colors sweep around a center point, like a pie chart:

background: conic-gradient(from 45deg, #ff6b6b, #feca57, #48dbfb, #ff6b6b);
Conic

Color Stops

You can control exactly where each color starts and ends using percentage or pixel values:

background: linear-gradient(90deg, #ee5a24 0%, #ee5a24 50%, #009432 50%, #009432 100%);

This creates a hard split between two colors at the 50% mark — no blending. This technique is useful for progress bars and split-color backgrounds.

Popular Gradient Combinations

Create Shadows & Gradients Visually

Use our free generators to design CSS effects visually and copy the code instantly.

Box Shadow Generator Gradient Generator

Best Practices

  1. Subtlety wins — The best shadows are barely noticeable. They create depth without drawing attention to themselves.
  2. Use colored shadows — Instead of black, try shadows that match the element's color for a more natural look: box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3)
  3. Limit gradient colors — Two or three colors usually look better than five. More colors risk looking amateurish.
  4. Test on different backgrounds — Shadows look different on white, gray, and dark backgrounds. Always test.
  5. Consider dark mode — Shadows need adjustment for dark themes. Lighter, more transparent shadows work better on dark backgrounds.

CSS shadows and gradients are fundamental skills for modern web design. Practice with our visual generators to build intuition, then apply these techniques to elevate your next project.