Have you ever looked at websites like Instagram, Stripe, or Apple and noticed how their buttons and cards don't just use one flat color, but smoothly transition from warm violet into fiery orange or deep oceanic blue? 🌅
In CSS, this smooth blending of colors is called a Gradient.
Gradients give modern websites depth, energy, and premium visual appeal without requiring heavy Photoshop image files.
In this lesson, you will master:
1
Linear Gradients (colors transition in a straight line or angle)
2
Radial Gradients (colors radiate outward from a central point like circular ripples)
To understand the difference between Linear and Radial gradients, remember these two everyday scenes:
Visual Architecture Blueprint
+-------------------------------------------------------------------------+
| THE TWO TYPES OF CSS GRADIENTS |
+-------------------------------------------------------------------------+
| 1. LINEAR GRADIENT --> THE SUNSET OVER THE CRICKET GROUND |
| At 6:00 PM, the sky blends in a straight line: |
| Golden Yellow at the horizon ──▶ |
| Rose Pink in the middle ──▶ |
| Deep Twilight Navy at the top! |
| |
| 2. RADIAL GRADIENT --> DIWALI RANGOLI / WATER DROPLET RIPPLES |
| Bright Yellow powder placed in the exact center,|
| radiating outward in circular rings of orange, |
| and finishing with dark magenta on the rim! |
+-------------------------------------------------------------------------+
Pro Tip
Important Rule to Remember:
In CSS, gradients are considered background images, not colors! Therefore, always apply gradients using background-image or the background shorthand, never background-color.
1. Linear Gradients (linear-gradient)
A Linear Gradient transitions colors in a straight direction: from top to bottom, left to right, or along any diagonal angle.
By default, the browser spaces out colors evenly. You can specify exact percentages to tell the browser where each color should begin and end:
1.custom-blend{
2background-image:linear-gradient(
3 to right,
4 #2563eb 0%,/* Blue starts at 0% */
5 #38bdf8 60%,/* Light blue reaches full strength at 60% */
6 #10b981 100% /* Emerald green finishes at 100% */
7);
8}
2. Radial Gradients (radial-gradient)
A Radial Gradient starts at a single central point and expands outward in circular or elliptical rings, just like ripples when you toss a pebble into a calm pond!
Basic Syntax:
1.circle-card{
2background-image:radial-gradient(shape at position, color1, color2);