Gradients (Linear & Radial)
CSS Gradients
Compose smooth gradients between color bands without using heavy graphic image assets:linear-gradient: Transitions colors along a linear angle.radial-gradient: Radiates colors from a central node out.Why does it matter?
Gradients add depth, modern aesthetics, and visual pop to websites. They are commonly used for modern buttons, card backgrounds, and dark overlays on top of background images to make text readable.Syntax Breakdown
Set gradients using thebackground or background-image properties:
background: linear-gradient(direction, color1, color2);linear-gradient(red, yellow) โ Blends from red (top) to yellow (bottom).linear-gradient(to right, red, yellow) โ Blends from left to right.linear-gradient(45deg, red, yellow) โ Blends along a 45-degree angle.Common Mistakes
linear-gradient(45deg, red, yellow).background-image or shorthand background property. Setting background-color: linear-gradient(...) will fail.Quick Reference
linear-gradient(angle, c1, c2) โ Linear transition.radial-gradient(shape, c1, c2) โ Radial circular transition.to right, to bottom left โ Direction keywords.Your Task
Set the `background` property of the `.gradient-box` class to a `linear-gradient` transitioning from `red` to `yellow`.
index.html
Type code above to start the lesson.
Live Preview