CSS Gradients

Loading concept...

šŸŽØ CSS Gradients: Painting with Code!

The Story of Colors That Flow

Imagine you have a magical paintbrush. But this isn’t any ordinary brush—when you dip it in one color and drag it across paper, it slowly changes into another color! That’s exactly what CSS gradients do. They let you blend colors together, creating smooth, beautiful transitions.

Think of a sunset. The sky starts orange near the sun, then fades to pink, then purple, and finally dark blue at the top. Nature doesn’t just stop one color and start another—it flows. CSS gradients work the same way!


🌈 The Five Gradient Superpowers

Gradient Type What It Does Real-Life Example
Linear Colors flow in a straight line A sunset on the horizon
Radial Colors spread from a center point A glowing light bulb
Conic Colors spin around like a wheel A color wheel or pie chart
Repeating Pattern repeats over and over Striped candy cane
Color Stops Control where colors appear Rainbow with exact bands

1ļøāƒ£ Linear Gradients: The Straight Path

What Is It?

A linear gradient paints colors in a straight line—like coloring a ruler from one end to the other.

The Basic Recipe

background: linear-gradient(
  direction,
  color1,
  color2
);

Simple Example

.sunset-box {
  background: linear-gradient(
    to right,
    orange,
    pink
  );
}

This creates a box that starts orange on the left and smoothly becomes pink on the right.

Direction Options

Direction What It Means
to right Left → Right
to left Right → Left
to bottom Top → Down
to top Bottom → Up
to bottom right Diagonal!
45deg 45° angle
180deg Straight down

Multiple Colors Example

.rainbow-bar {
  background: linear-gradient(
    to right,
    red,
    orange,
    yellow,
    green,
    blue
  );
}

This creates a rainbow! Colors flow left to right: red → orange → yellow → green → blue.

graph TD A[Start Color] --> B[Middle Colors] B --> C[End Color] style A fill:#ff6b6b style B fill:#ffd93d style C fill:#6bcb77

2ļøāƒ£ Radial Gradients: The Glowing Circle

What Is It?

A radial gradient starts from a center point and spreads outward—like dropping a pebble in water and watching ripples grow!

The Basic Recipe

background: radial-gradient(
  shape at position,
  color1,
  color2
);

Simple Example

.glowing-orb {
  background: radial-gradient(
    circle,
    yellow,
    orange
  );
}

This creates a glowing sun! Yellow in the center, fading to orange at the edges.

Shape Options

Shape What It Looks Like
circle Perfect round glow
ellipse Stretched oval glow

Position Examples

/* Glow from top-left corner */
background: radial-gradient(
  circle at top left,
  white,
  blue
);

/* Glow from exact spot */
background: radial-gradient(
  circle at 25% 75%,
  pink,
  purple
);

Spotlight Effect

.spotlight {
  background: radial-gradient(
    circle at center,
    white 0%,
    transparent 50%,
    black 100%
  );
}

This creates a spotlight in the middle of darkness!


3ļøāƒ£ Conic Gradients: The Spinning Wheel

What Is It?

A conic gradient spins colors around a center point—like a pizza with different colored slices, or a color wheel!

The Basic Recipe

background: conic-gradient(
  from angle at position,
  color1,
  color2
);

Simple Example

.color-wheel {
  background: conic-gradient(
    red,
    yellow,
    green,
    blue,
    red
  );
  border-radius: 50%;
}

This creates a complete color wheel! Notice we end with red again so it connects smoothly.

Pie Chart Example

.pie-chart {
  background: conic-gradient(
    red 0deg 90deg,
    blue 90deg 200deg,
    green 200deg 360deg
  );
  border-radius: 50%;
}

This creates a pie chart with three slices!

graph TD A[Start at 0°] --> B[Spin Clockwise] B --> C[Colors Change as We Spin] C --> D[Return to Start at 360°]

Starting From Different Angles

/* Start from the top */
background: conic-gradient(
  from 0deg,
  red, yellow, green
);

/* Start from the right */
background: conic-gradient(
  from 90deg,
  red, yellow, green
);

4ļøāƒ£ Repeating Gradients: Patterns Forever!

What Is It?

Repeating gradients take a small pattern and repeat it over and over—like wallpaper or a candy cane’s stripes!

Three Types of Repeating

Type Creates
repeating-linear-gradient Repeating stripes
repeating-radial-gradient Repeating circles
repeating-conic-gradient Repeating wheel segments

Striped Pattern

.candy-stripes {
  background: repeating-linear-gradient(
    45deg,
    red 0px,
    red 10px,
    white 10px,
    white 20px
  );
}

This creates diagonal red and white stripes—like a candy cane!

Bullseye Pattern

.bullseye {
  background: repeating-radial-gradient(
    circle,
    red 0px,
    red 10px,
    white 10px,
    white 20px
  );
}

This creates a target with alternating red and white rings!

Sunburst Pattern

.sunburst {
  background: repeating-conic-gradient(
    gold 0deg,
    gold 15deg,
    orange 15deg,
    orange 30deg
  );
}

This creates alternating gold and orange rays spinning outward!


5ļøāƒ£ Color Stops: Taking Control

What Are They?

Color stops tell the gradient exactly where each color should be. Without them, colors are spread evenly. With them, YOU control the mix!

The Basic Idea

background: linear-gradient(
  to right,
  red 0%,      /* Red starts at 0% */
  red 30%,     /* Red stays until 30% */
  blue 30%,    /* Blue starts at 30% */
  blue 100%    /* Blue goes to the end */
);

This creates a hard line between red and blue at the 30% mark—no blending!

Soft vs Hard Stops

Soft Stop (Smooth Blend):

background: linear-gradient(
  to right,
  red 0%,
  blue 100%
);

Hard Stop (Sharp Line):

background: linear-gradient(
  to right,
  red 0%,
  red 50%,
  blue 50%,
  blue 100%
);

Using Different Units

/* Percentages */
background: linear-gradient(
  red 25%,
  blue 75%
);

/* Pixels */
background: linear-gradient(
  red 50px,
  blue 150px
);

Color Stop Hint (Midpoint)

/* Move blend midpoint to 25% */
background: linear-gradient(
  red,
  25%,
  blue
);

This makes the blend happen faster—more blue, less red!

graph TD A["0% - Color 1 Starts"] --> B["Color Stop Position"] B --> C["Blend Zone"] C --> D["100% - Color 2 Ends"]

šŸŽÆ Quick Reference Table

What You Want Code Pattern
Left to right blend linear-gradient(to right, red, blue)
Top to bottom blend linear-gradient(to bottom, red, blue)
Diagonal blend linear-gradient(45deg, red, blue)
Center glow radial-gradient(circle, white, black)
Color wheel conic-gradient(red, yellow, green, blue, red)
Stripes repeating-linear-gradient(45deg, red 0 10px, white 10px 20px)
Hard color edge linear-gradient(red 50%, blue 50%)

šŸš€ Pro Tips

  1. Combine gradients! You can layer multiple gradients:
background:
  linear-gradient(rgba(0,0,0,0.5), transparent),
  radial-gradient(circle, yellow, orange);
  1. Use transparent for fading effects:
background: linear-gradient(
  red,
  transparent
);
  1. Make patterns with repeating gradients for textures without images.

  2. Conic gradients + border-radius: 50% = instant pie charts!


šŸŽ‰ You Did It!

Now you know how to:

  • Make colors flow in straight lines with linear gradients
  • Create glowing circles with radial gradients
  • Spin colors like a wheel with conic gradients
  • Build endless patterns with repeating gradients
  • Control exactly where colors appear with color stops

Go paint your web pages with the power of gradients! 🌈

Loading story...

No Story Available

This concept doesn't have a story yet.

Story Preview

Story - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

Interactive Preview

Interactive - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

No Interactive Content

This concept doesn't have interactive content yet.

Cheatsheet Preview

Cheatsheet - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

No Cheatsheet Available

This concept doesn't have a cheatsheet yet.

Quiz Preview

Quiz - Premium Content

Please sign in to view this concept and start learning.

Upgrade to Premium to unlock full access to all content.

No Quiz Available

This concept doesn't have a quiz yet.