CSS gradients allow you to create smooth transitions between two or more colors without using any images. They are lightweight, scalable, and can be customized in countless ways - making them an essential tool for modern web design. Gradients can be applied anywhere you can use a background, such as buttons, sections, or entire pages.
There are three main types of CSS gradients:
A linear gradient is the most common type of gradient. It moves colors in a straight line - horizontally, vertically, or diagonally. The syntax is:
background: linear-gradient(direction, color1, color2, ...);
Example:
.element {
background: linear-gradient(to right, #00b4db, #0083b0);
}
This example creates a horizontal gradient from left to right, transitioning from light blue (#00b4db) to darker blue (#0083b0).
You can control the gradient direction using keywords or angles:
to right – left to rightto left – right to leftto bottom – top to bottom45deg – diagonal gradient at a 45-degree angleExample using an angle:
background: linear-gradient(135deg, #f093fb, #f5576c);
You can add more than two colors to a gradient and control where each one appears:
background: linear-gradient(to right, #ff9a9e 0%, #fad0c4 50%, #fad0c4 100%);
This creates a three-color gradient that blends smoothly from pink to soft peach.
A radial gradient radiates from a central point outward. The syntax is:
background: radial-gradient(shape size at position, color1, color2, ...);
Example:
.element {
background: radial-gradient(circle at center, #ff9966, #ff5e62);
}
This creates a circular gradient centered in the middle of the element, transitioning from orange to deep red.
You can also move the gradient’s origin:
background: radial-gradient(circle at top left, #00c6ff, #0072ff);
This places the gradient’s center in the top-left corner.
A conic gradient (or angular gradient) is a newer CSS feature that creates color transitions around a central point — similar to slices of a pie or a color wheel.
background: conic-gradient(from 0deg, #ff9a9e, #fad0c4, #ff9a9e);
You can specify where the gradient starts using from and control the center position with at.
background: conic-gradient(from 90deg at 50% 50%, #f6d365, #fda085, #f6d365);
You can create repeating gradients using the repeating-linear-gradient(), repeating-radial-gradient(), or repeating-conic-gradient() functions. These are great for striped backgrounds, patterns, or textures.
background: repeating-linear-gradient( 45deg, #606dbc, #606dbc 10px, #465298 10px, #465298 20px );
This produces a repeating diagonal stripe pattern.
You can layer multiple gradients by separating them with commas. Each layer is rendered on top of the previous one.
background:
linear-gradient(to right, rgba(0,0,0,0.5), rgba(0,0,0,0.1)),
url('image.jpg');
background-blend-mode: overlay;
This example applies a semi-transparent gradient on top of an image, creating a stylish overlay effect.
CSS gradients are supported in all modern browsers. Older browsers may require vendor prefixes such as -webkit- or -moz-, but in most cases, they are no longer necessary.
background-blend-mode for artistic results.CSS gradients are a versatile and visually appealing way to enhance your web design. They replace static images with flexible, high-performance color transitions that scale beautifully across all devices. Whether you’re designing buttons, backgrounds, or animated effects, mastering gradients will add depth, style, and professionalism to your projects.