CSS Gradients
Gradients in CSS allow you to create smooth transitions between colors without using images. You can create linear, radial, and conic gradients.
1. Types of Gradients in CSS
✅ A. Linear Gradient
A linear gradient transitions colors in a straight line.
Example:
✅ Creates a left-to-right red-to-blue gradient.
š¹ Direction Options
Keyword | Effect |
---|---|
to right | Left → Right |
to left | Right → Left |
to top | Bottom → Top |
to bottom | Top → Bottom (default) |
45deg | Diagonal (45 degrees) |
Example with angle:
✅ Creates a diagonal gradient from orange to purple.
✅ B. Radial Gradient
A radial gradient spreads from the center outward.
Example:
✅ Creates a circular yellow-to-green gradient.
š¹ Radial Gradient Shapes
Shape | Effect |
---|---|
circle | Perfect circle gradient. |
ellipse | Oval shape (default). |
Example with position:
✅ Starts from the top instead of the center.
✅ C. Conic Gradient (CSS3)
A conic gradient creates a color wheel effect.
Example:
✅ Creates a circular gradient like a pie chart.
Example with angle stops:
✅ Starts at 45 degrees with 50% yellow.
2. Adding More Colors
You can add multiple colors:
✅ Creates a rainbow-like gradient.
3. Using Transparency (RGBA)
You can use semi-transparent colors:
✅ Creates a gradient with transparency.
4. Repeating Gradients
If you need a striped effect, use repeating-linear-gradient()
:
✅ Repeats a red & blue striped pattern every 20px.
5. Applying Gradients to Text
You can make text gradient-colored:
✅ The text will have a gradient fill instead of a solid color.
6. Browser Support
✅ All modern browsers support linear and radial gradients.
šø Conic gradients require CSS3 and may not work in older browsers.