Mastering CSS Gradients: A Visual Guide
Learn how to create stunning linear and radial gradients in CSS. Theory, examples, and tools to generate code automatically.
Table of Contents
CSS gradients are one of the most powerful tools for adding depth and dynamism to your web designs without the need for heavy image files.
What is a CSS Gradient?
A gradient is simply a smooth transition between two or more colors. In CSS, gradients are treated as background images (background-image), meaning you can stack them, resize them, and repeat them.
Main Types
- Linear Gradient: Colors change along a straight line (top to bottom, left to right, or diagonally).
- Radial Gradient: Colors radiate from a central point outward, in a circular or elliptical shape.
- Conic Gradient: Colors rotate around a central point (like a pie chart).
Basic Syntax
Linear Gradient
.linear-bg {
background: linear-gradient(90deg, #3b82f6, #8b5cf6);
}
90deg: The direction. It can be degrees or keywords liketo right,to bottom left.#3b82f6,#8b5cf6: The color stops.
Radial Gradient
.radial-bg {
background: radial-gradient(circle, #3b82f6, #8b5cf6);
}
Tips for Professional Gradients
1. Avoid the “Gray Dead Zone”
When you mix two colors of very different hues (e.g., Cyan and Red) without passing through an intermediate color, the center can look grayish and dull. Solution: Add an intermediate “color stop” that bridges the gap between the two.
2. Use Interesting Angles
Perfectly vertical gradients (0deg or 180deg) often look a bit outdated. Try gentle diagonal angles (e.g., 135deg) for a more modern look.
Recommended Tool
Creating complex gradients by writing code by hand can be tedious, especially when you’re trying to adjust the percentages of each color.
That’s why we’ve created our own CSS Gradient Generator.
[!TIP] Try it now: CSS Gradient Generator
Design your gradients visually, add multiple colors, adjust angles, and copy ready-to-use CSS or Tailwind code.
Practical Example: Gradient Button
.btn-gradient {
background: linear-gradient(45deg, #FF512F 0%, #DD2476 100%);
color: white;
padding: 15px 30px;
border: none;
border-radius: 5px;
font-weight: bold;
cursor: pointer;
transition: transform 0.3s;
}
.btn-gradient:hover {
transform: scale(1.05);
}
Gradients are essential in modern design. Experiment and bring your web to life!