Gradients & Shadows
Add depth and visual interest with gradients and shadows. These CSS features create sophisticated designs without images.
🎨 Linear Gradients
/* Basic linear gradient */
.gradient {
background: linear-gradient(red, blue);
}
/* Direction keywords */
.to-right {
background: linear-gradient(to right, red, blue);
}
.to-bottom-right {
background: linear-gradient(to bottom right, red, blue);
}
/* Angle (0deg = up, 90deg = right, 180deg = down, 270deg = left) */
.angle {
background: linear-gradient(45deg, red, blue);
background: linear-gradient(135deg, red, blue);
}
/* Multiple colors */
.rainbow {
background: linear-gradient(
to right,
red, orange, yellow, green, blue, indigo, violet
);
}
/* Color stops (positions) */
.stops {
background: linear-gradient(
to right,
red 0%,
orange 20%,
yellow 40%,
green 60%,
blue 80%,
violet 100%
);
}
/* Sharp transitions */
.stripes {
background: linear-gradient(
to right,
red 0%, red 33%,
white 33%, white 66%,
blue 66%, blue 100%
);
}
/* Transparent gradients */
.fade {
background: linear-gradient(
to bottom,
rgba(0,0,0,0),
rgba(0,0,0,0.8)
);
}
🔘 Radial Gradients
/* Basic radial gradient */
.radial {
background: radial-gradient(red, blue);
}
/* Shape: circle or ellipse */
.circle {
background: radial-gradient(circle, red, blue);
}
.ellipse {
background: radial-gradient(ellipse, red, blue);
}
/* Size keywords */
.closest-side {
background: radial-gradient(closest-side, red, blue);
}
.closest-corner {
background: radial-gradient(closest-corner, red, blue);
}
.farthest-side {
background: radial-gradient(farthest-side, red, blue);
}
.farthest-corner {
background: radial-gradient(farthest-corner, red, blue);
}
/* Explicit size */
.sized {
background: radial-gradient(100px 50px, red, blue);
}
/* Position */
.positioned {
background: radial-gradient(circle at top left, red, blue);
background: radial-gradient(circle at 75% 25%, red, blue);
background: radial-gradient(circle at 100px 50px, red, blue);
}
/* Multiple colors with stops */
.sun {
background: radial-gradient(
circle,
yellow 0%,
orange 30%,
red 60%,
transparent 80%
);
}
🎡 Conic Gradients
/* Basic conic gradient */
.conic {
background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
}
/* Starting angle */
.angled {
background: conic-gradient(from 45deg, red, blue);
}
/* Position */
.positioned {
background: conic-gradient(at 25% 25%, red, blue);
}
/* Color stops */
.pie-chart {
background: conic-gradient(
red 0deg 90deg,
blue 90deg 180deg,
green 180deg 270deg,
yellow 270deg 360deg
);
}
/* Checkerboard pattern */
.checkerboard {
background: conic-gradient(
#000 0deg 90deg,
#fff 90deg 180deg,
#000 180deg 270deg,
#fff 270deg 360deg
);
}
/* Color wheel */
.color-wheel {
background: conic-gradient(
hsl(0, 100%, 50%),
hsl(60, 100%, 50%),
hsl(120, 100%, 50%),
hsl(180, 100%, 50%),
hsl(240, 100%, 50%),
hsl(300, 100%, 50%),
hsl(360, 100%, 50%)
);
border-radius: 50%;
}
🔁 Repeating Gradients
/* Repeating linear gradient */
.stripes {
background: repeating-linear-gradient(
45deg,
red 0px,
red 10px,
white 10px,
white 20px
);
}
/* Barbershop pole */
.pole {
background: repeating-linear-gradient(
45deg,
#ff0000 0px,
#ff0000 20px,
#ffffff 20px,
#ffffff 40px,
#0000ff 40px,
#0000ff 60px
);
}
/* Repeating radial gradient */
.rings {
background: repeating-radial-gradient(
circle,
red 0px,
red 10px,
white 10px,
white 20px
);
}
/* Repeating conic gradient */
.spinner {
background: repeating-conic-gradient(
from 0deg,
red 0deg 10deg,
white 10deg 20deg
);
border-radius: 50%;
}
🎯 Multiple Gradients
/* Layer multiple gradients */
.layered {
background:
linear-gradient(45deg, transparent 30%, blue 30%),
linear-gradient(-45deg, transparent 30%, red 30%);
}
/* Complex patterns */
.pattern {
background:
linear-gradient(90deg, rgba(255,255,255,.1) 1px, transparent 1px),
linear-gradient(rgba(255,255,255,.1) 1px, transparent 1px),
linear-gradient(45deg, #000 25%, transparent 25%),
linear-gradient(-45deg, #000 25%, transparent 25%);
background-size: 20px 20px, 20px 20px, 10px 10px, 10px 10px;
}
/* Overlay gradient on image */
.hero {
background:
linear-gradient(to bottom, rgba(0,0,0,0.5), rgba(0,0,0,0.8)),
url('image.jpg');
background-size: cover;
}
💫 Box Shadow
/* Basic shadow */
.shadow {
box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
/* offset-x offset-y blur color */
}
/* Spread radius */
.spread {
box-shadow: 2px 2px 5px 3px rgba(0,0,0,0.3);
/* offset-x offset-y blur spread color */
}
/* No offset (glow) */
.glow {
box-shadow: 0 0 10px rgba(0,123,255,0.5);
}
/* Multiple shadows */
.multiple {
box-shadow:
0 1px 3px rgba(0,0,0,0.12),
0 1px 2px rgba(0,0,0,0.24);
}
/* Inset shadow (inside) */
.inset {
box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}
/* No shadow */
.none {
box-shadow: none;
}
/* Examples */
/* Subtle card shadow */
.card {
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
/* Elevated card */
.card-elevated {
box-shadow: 0 10px 20px rgba(0,0,0,0.15);
}
/* Pressed button */
.button-pressed {
box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}
/* Neon glow */
.neon {
box-shadow:
0 0 5px #fff,
0 0 10px #fff,
0 0 20px #0ff,
0 0 30px #0ff,
0 0 40px #0ff;
}
/* Layered depth */
.layered-shadow {
box-shadow:
0 1px 1px rgba(0,0,0,0.11),
0 2px 2px rgba(0,0,0,0.11),
0 4px 4px rgba(0,0,0,0.11),
0 8px 8px rgba(0,0,0,0.11),
0 16px 16px rgba(0,0,0,0.11);
}
✍️ Text Shadow
/* Basic text shadow */
.text-shadow {
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
/* offset-x offset-y blur color */
}
/* No blur */
.sharp {
text-shadow: 2px 2px 0 #000;
}
/* Multiple text shadows */
.multiple {
text-shadow:
1px 1px 0 #ccc,
2px 2px 0 #c9c9c9,
3px 3px 0 #bbb,
4px 4px 0 #b9b9b9,
5px 5px 0 #aaa;
}
/* Glow effect */
.glow {
text-shadow: 0 0 10px rgba(255,255,255,0.8);
}
/* Neon text */
.neon-text {
color: #fff;
text-shadow:
0 0 5px #fff,
0 0 10px #fff,
0 0 20px #ff00de,
0 0 30px #ff00de,
0 0 40px #ff00de;
}
/* 3D text */
.text-3d {
text-shadow:
1px 1px 0 #ccc,
2px 2px 0 #c9c9c9,
3px 3px 0 #bbb,
4px 4px 0 #b9b9b9,
5px 5px 5px rgba(0,0,0,0.5);
}
/* Embossed text */
.embossed {
color: #666;
text-shadow: 1px 1px 0 #fff;
}
/* Engraved text */
.engraved {
color: #ccc;
text-shadow: -1px -1px 0 #000;
}
/* Outline text */
.outline {
color: #fff;
text-shadow:
-1px -1px 0 #000,
1px -1px 0 #000,
-1px 1px 0 #000,
1px 1px 0 #000;
}
🎭 Drop Shadow (Filter)
/* drop-shadow works on images with transparency */
.image-shadow {
filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.5));
}
/* Multiple drop shadows */
.multiple-drop {
filter:
drop-shadow(2px 2px 4px rgba(0,0,0,0.3))
drop-shadow(0 0 10px rgba(0,123,255,0.5));
}
/* Difference from box-shadow */
/* box-shadow: Rectangle around element */
.box {
box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
/* drop-shadow: Follows alpha channel of image */
.drop {
filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}
/* PNG with transparency */
img.logo {
filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
}
🎯 Practical Examples
/* Card with gradient background */
.gradient-card {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 2rem;
border-radius: 8px;
box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}
/* Button with gradient */
.gradient-button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 12px 24px;
border: none;
border-radius: 4px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
transition: box-shadow 0.3s, transform 0.3s;
}
.gradient-button:hover {
box-shadow: 0 6px 10px rgba(0,0,0,0.15);
transform: translateY(-2px);
}
/* Glassmorphism effect */
.glass {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 16px;
padding: 2rem;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}
/* Hero section with overlay */
.hero {
background:
linear-gradient(
to bottom,
rgba(0,0,0,0.3),
rgba(0,0,0,0.7)
),
url('hero-image.jpg');
background-size: cover;
background-position: center;
color: white;
padding: 100px 20px;
text-align: center;
}
/* Animated gradient background */
@keyframes gradient-shift {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
.animated-gradient {
background: linear-gradient(
-45deg,
#ee7752, #e73c7e, #23a6d5, #23d5ab
);
background-size: 400% 400%;
animation: gradient-shift 15s ease infinite;
}
/* Progress bar with gradient */
.progress-bar {
height: 8px;
background: #e0e0e0;
border-radius: 4px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
border-radius: 4px;
width: 60%;
box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
}
/* Tag with gradient border */
.gradient-border {
position: relative;
padding: 10px 20px;
border-radius: 8px;
background: white;
}
.gradient-border::before {
content: "";
position: absolute;
inset: 0;
border-radius: 8px;
padding: 2px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
}
/* Loading skeleton with gradient */
@keyframes skeleton-loading {
0% { background-position: -200px 0; }
100% { background-position: calc(200px + 100%) 0; }
}
.skeleton {
background: linear-gradient(
90deg,
#f0f0f0 0px,
#e0e0e0 40px,
#f0f0f0 80px
);
background-size: 200px 100%;
animation: skeleton-loading 1.5s infinite;
}
/* Text with gradient */
.gradient-text {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
font-size: 3rem;
font-weight: bold;
}
/* Material Design elevation */
.elevation-1 {
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.elevation-2 {
box-shadow: 0 4px 8px rgba(0,0,0,0.12);
}
.elevation-3 {
box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}
.elevation-4 {
box-shadow: 0 8px 16px rgba(0,0,0,0.18);
}
.elevation-5 {
box-shadow: 0 12px 24px rgba(0,0,0,0.2);
}
/* Neumorphism */
.neumorphic {
background: #e0e0e0;
border-radius: 20px;
padding: 2rem;
box-shadow:
8px 8px 16px #bebebe,
-8px -8px 16px #ffffff;
}
.neumorphic-inset {
background: #e0e0e0;
border-radius: 20px;
padding: 2rem;
box-shadow:
inset 8px 8px 16px #bebebe,
inset -8px -8px 16px #ffffff;
}
/* Pricing card with gradient accent */
.pricing-card {
background: white;
border-radius: 12px;
padding: 2rem;
box-shadow: 0 4px 12px rgba(0,0,0,0.08);
position: relative;
overflow: hidden;
}
.pricing-card::before {
content: "";
position: absolute;
top: 0;
left: 0;
right: 0;
height: 4px;
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
}
/* Image overlay gradient */
.image-overlay {
position: relative;
}
.image-overlay::after {
content: "";
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 50%;
background: linear-gradient(
to bottom,
transparent,
rgba(0,0,0,0.8)
);
}
/* Badge with shadow */
.badge {
display: inline-block;
padding: 4px 12px;
border-radius: 12px;
font-size: 0.875rem;
font-weight: 600;
}
.badge-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}
.badge-success {
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
color: white;
box-shadow: 0 2px 8px rgba(17, 153, 142, 0.3);
}
🎯 Key Takeaways
- Linear gradients: Transition colors in straight line (angles or keywords)
- Radial gradients: Circular or elliptical color transitions
- Conic gradients: Rotate around center point (pie charts, color wheels)
- box-shadow: Shadow around element rectangle
- text-shadow: Shadow on text characters
- drop-shadow: Filter that follows alpha channel
- Multiple shadows: Comma-separated for layered effects
- Performance: Gradients are faster than images