Effects & Animation Lesson 29 of 33
CSS Gradients and Shadows
Create smooth color blends with linear, radial and conic gradients, and add depth with box-shadow and text-shadow — without any image files.
Gradients and shadows add depth and polish to a design, and they're made entirely with CSS: no image files to download, so they cost almost no data. Used lightly, they make buttons feel clickable and cards feel like they float above the page.
Linear gradients
A linear gradient blends colors along a straight line. It's used as a background (it's technically an image, not a color):
background: linear-gradient(direction, color1, color2, ...);
<style>
.g { height: 60px; border-radius: 10px; margin-bottom: 8px; color: white; font: bold 14px monospace; display: grid; place-items: center; }
</style>
<div class="g" style="background: linear-gradient(#0f5c4d, #7fd1b9);">top → bottom (default)</div>
<div class="g" style="background: linear-gradient(to right, #0038A8, #CE1126);">to right</div>
<div class="g" style="background: linear-gradient(135deg, #f2b33d, #e2552d);">135deg (diagonal)</div>
<div class="g" style="background: linear-gradient(to right, #0038A8, #ffffff, #CE1126);">three colors</div>
The direction can be a keyword (to right, to bottom left) or an angle (90deg points right, 180deg points down).
Color stops
You can say where each color starts. Two colors at the same position create a hard line instead of a blend, which is how you make stripes:
<style>
.flag { height: 120px; border-radius: 10px; background: linear-gradient(#0038A8 0% 50%, #CE1126 50% 100%); }
</style>
<div class="flag"></div>
Radial gradients
A radial gradient spreads out from a center point, like light from a bulb:
<style>
.r { width: 160px; height: 160px; display: inline-block; border-radius: 16px; margin-right: 10px; }
</style>
<div class="r" style="background: radial-gradient(#FCD116, #e2552d);"></div>
<div class="r" style="background: radial-gradient(circle at top left, #7fd1b9, #0f5c4d);"></div>
Conic gradients
A conic gradient sweeps colors around a center point, like the hands of a clock. Combined with border-radius: 50%, it makes a simple pie chart:
<style>
.pie {
width: 170px; height: 170px; border-radius: 50%;
background: conic-gradient(#0f5c4d 0 45%, #f2b33d 45% 75%, #CE1126 75% 100%);
}
.legend { font-family: Arial, sans-serif; }
</style>
<div class="pie"></div>
<p class="legend">🟢 Walk 45% · 🟡 Jeepney 30% · 🔴 Tricycle 25%</p>
box-shadow
box-shadow adds a shadow around an element's box. Its values, in order:
box-shadow: x-offset y-offset blur spread color;
box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.15);
- x / y offset — how far the shadow moves right and down
- blur — how soft the edge is (0 = sharp)
- spread — makes the shadow bigger or smaller (optional)
- color — usually a see-through black
<style>
.card { display: inline-block; width: 130px; height: 90px; margin: 14px; border-radius: 12px; background: white; font: 13px monospace; padding: 8px; }
</style>
<div class="card" style="box-shadow: 0 1px 3px rgba(0,0,0,0.12);">subtle</div>
<div class="card" style="box-shadow: 0 6px 18px rgba(0,0,0,0.15);">medium</div>
<div class="card" style="box-shadow: 0 16px 40px rgba(0,0,0,0.25);">floating</div>
<div class="card" style="box-shadow: 6px 6px 0 #0f5c4d; border: 2px solid #0f5c4d;">hard offset</div>
Inset and multiple shadows
The keyword inset puts the shadow inside the box, as if it were pressed in. You can also stack several shadows separated by commas:
<style>
.pressed { display: inline-block; padding: 18px 24px; border-radius: 12px; background: #f3f6f4; box-shadow: inset 0 3px 8px rgba(0,0,0,0.2); font-family: Arial, sans-serif; margin: 10px; }
.glow { display: inline-block; padding: 18px 24px; border-radius: 12px; background: #0f5c4d; color: white; font-family: Arial, sans-serif; margin: 10px;
box-shadow: 0 0 0 4px #f2b33d, 0 10px 24px rgba(15, 92, 77, 0.45); }
</style>
<div class="pressed">inset</div>
<div class="glow">ring + glow</div>
text-shadow
text-shadow works the same way but has no spread value: x y blur color. A small, soft shadow helps white text stay readable on top of a photo:
.hero h1 { text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5); }
Putting it together: a gradient button
<style>
.btn {
padding: 14px 26px;
border: 0;
border-radius: 999px;
color: white;
font: bold 17px Arial, sans-serif;
background: linear-gradient(135deg, #127a65, #0f5c4d);
box-shadow: 0 6px 16px rgba(15, 92, 77, 0.35);
cursor: pointer;
}
.btn:hover { box-shadow: 0 10px 24px rgba(15, 92, 77, 0.45); }
</style>
<button class="btn">Mag-enroll na! →</button>
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04