CSS: CSS Gradients & Shadows

Last updated: 2026-10-13

Properties in this section: text-shadow box-shadow

1. Gradients

Gradients create smooth transitions between colors. CSS provides two main gradient functions.

(1) linear-gradient

Creates a straight-line gradient:

▶ Example

▶ Try it Yourself

(2) radial-gradient

Creates a circular/elliptical gradient:

▶ Example

▶ Try it Yourself

2. Shadows

(1) box-shadow

Adds shadow effects to elements:

▶ Example

▶ Try it Yourself

(2) text-shadow

Adds shadow to text:

▶ Example

▶ Try it Yourself

Properties in this section: text-shadow box-shadow

❓ FAQ

Q Any tools for creating gradients?
A Recommended: cssgradient.io and webgradients.com — drag-and-drop gradient generators. Copy code directly. Studying others' gradient schemes builds intuition for angles and color stops.
Q Can box-shadow have multiple shadows?
A Yes, separate with commas: box-shadow: 0 2px 8px rgba(0,0,0,0.1), 0 8px 32px rgba(0,0,0,0.08); creates a double-shadow effect. Shadows stack in declaration order — earlier ones on top.
Q What's the difference between text-shadow and box-shadow?
A text-shadow acts on text only, no spread parameter, no inset support. box-shadow acts on the entire element box, has spread, supports inset. Similar syntax but different capabilities.

📖 Summary

📝 Exercises

  1. Create a gradient button — left-to-right color transition, direction changes on hover.
  2. Create a "floating card" — subtle shadow by default, deeper shadow + lift on hover.
  3. Use repeating-linear-gradient to create a striped background pattern.
  4. Add text-shadow or drop-shadow glow effect to a PNG icon or text.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏