CSS Gradient Generator
Design a linear or radial gradient, preview it live and copy the CSS declaration into your own stylesheet.
Generated gradient
The preview and the declaration update as soon as a control changes.
Gradient syntax at a glance
| Function | Required arguments | Default direction | Example |
|---|---|---|---|
linear-gradient() | Two or more color stops | To bottom (180deg) | linear-gradient(90deg, #3b82f6, #8b5cf6) |
radial-gradient() | Two or more color stops | Ellipse at center, farthest corner | radial-gradient(circle, #3b82f6, #8b5cf6) |
conic-gradient() | Two or more color stops | Starts at 12 o'clock | conic-gradient(#3b82f6, #8b5cf6) |
repeating-linear-gradient() | Stops with a length or percentage | To bottom (180deg) | repeating-linear-gradient(45deg, #eee 0 10px, #fff 10px 20px) |
A gradient is an image, not a color
CSS gradients belong to the image data type. That single fact explains most of their behaviour, from how they stack to why they do not animate smoothly.
How a CSS gradient is built
A gradient function produces an image at render time. The browser draws a gradient line or a set of concentric shapes, places each color stop along it and interpolates the colors in between. No image file is downloaded, and no element is added to the page.
Because the result is an image, it is assigned with background-image or with the background shorthand, not with background-color.
A gradient can therefore sit on top of a solid color, or several gradients can be layered in one declaration, with the first one painted on top.
background-image: linear-gradient(90deg, #3b82f6, #8b5cf6);
background-color: #3b82f6;
The declaration above keeps a solid fallback in place. If you use the background shorthand after the color, it resets every background property, including
background-color, to its initial value. That is why a fallback color written before a shorthand gradient often disappears.
Linear gradients and the angle syntax
A linear gradient runs along a straight line. The angle states where the gradient line points, measured clockwise from the upward direction. Zero degrees points to the top, so the last color sits at the top of the box. Ninety degrees points to the right, which puts the first color on the left.
Direction keywords are easier to read and produce the same result: to top, to right, to bottom and to left.
Corner keywords such as to top right are allowed too, and their exact angle depends on the aspect ratio of the element.
| Angle | Keyword | Gradient line points | First color appears |
|---|---|---|---|
0deg | to top | Upward | At the bottom |
45deg | to top right | Up and to the right | At the bottom left |
90deg | to right | To the right | At the left edge |
180deg | to bottom | Downward | At the top edge |
270deg | to left | To the left | At the right edge |
The visible transition is perpendicular to the gradient line, not along it. For a 90-degree gradient the colors change from left to right, and each vertical slice of the box has one flat color.
Radial gradients: shape, size and position
A radial gradient expands from a center point. The generator uses radial-gradient(circle, color1, color2), which is the simplest form: a circle centered in the element,
sized to reach the farthest corner by default.
The full syntax accepts three optional pieces before the color stops: the shape, the size and the position. Writing them explicitly makes a gradient predictable when the element changes size.
| Keyword | What it controls | Typical effect |
|---|---|---|
circle | Shape | Keeps a perfect circle at any aspect ratio |
ellipse | Shape | Stretches to match the box; the default |
closest-side | Size | Ends exactly at the nearest edge |
farthest-side | Size | Ends at the farthest edge, still inside the box |
closest-corner | Size | Ends at the nearest corner |
farthest-corner | Size | Ends at the farthest corner; the default |
at 30% 70% | Position | Moves the center point |
For a soft highlight, place a light circle at the top left and let the base color take over: radial-gradient(circle at 20% 20%, #ffffff, #3b82f6).
If the gradient is meant to look like a light source, keep the change subtle; a hard bright center reads as a button state, not as lighting.
Color stops, hard stops and transparency
Each color can carry a position, written as a length or a percentage. Two stops at the same position create a hard edge instead of a fade, which is how CSS draws stripes without an image file.
linear-gradient(90deg, #3b82f6 0%, #8b5cf6 100%)
linear-gradient(90deg, #3b82f6 0 50%, #8b5cf6 50% 100%)
linear-gradient(90deg, #3b82f6, rgba(59, 130, 246, 0))
The second example is a hard stop: blue fills the first half and violet fills the second half. The third fades the same blue to full transparency, which is useful for image overlays and masks.
Prefer the named color with zero alpha over the keyword transparent. The keyword means transparent black, so a fade from a saturated color to
transparent can pass through a darker, greyer shade on browsers that interpolate unpremultiplied values. Naming the same hue with alpha 0 avoids that.
Performance, banding and text contrast
A full-screen gradient is cheap to paint but not free: the browser still rasterizes it on every repaint. Large gradients on elements that animate, such as a background that moves on scroll, are more expensive than a solid color. Test on a mid-range phone before shipping a full-page animated gradient.
Banding is the visible stair-step between two close colors. It comes from 8-bit color depth: a long, low-contrast gradient has fewer distinct values than the eye can resolve smoothly. Shortening the distance between the two colors, adding a third intermediate stop, or laying a very subtle noise texture over the gradient reduces the effect.
Text over a gradient must stay readable across the whole area. The contrast can pass at the top of the box and fail at the bottom, because the background color changes underneath the letters. Check the lightest and darkest points of the gradient separately. WCAG 2.2 asks for 4.5:1 for normal text and 3:1 for large text, and a gradient usually needs a scrim or a solid plate to reach those numbers.
Gradients also do not transition the way colors do. Most engines cannot interpolate between two gradient images, so a CSS transition on background jumps from one to the other.
Fade the opacity of a pseudo-element that holds the second gradient instead.
Common gradient mistakes
| Mistake | Why it fails | Correct approach |
|---|---|---|
| Unitless angle | linear-gradient(90, ...) is invalid; zero is the only unitless length allowed | Write 90deg |
| One color stop | A gradient needs at least two colors to interpolate | Add a second color or a position |
background-color with a gradient | The property only accepts a color | Use background-image |
| Fallback color lost | The background shorthand resets earlier values | Declare the color after, or use longhand properties |
| Stops out of order | Browsers clamp positions so the fade looks compressed | Keep positions ascending |
Fading to transparent | Interpolates toward transparent black | Use the same color with alpha 0 |
Vendor prefixes such as -webkit-linear-gradient are not needed for current browsers. Keep them out of new code unless you still support a legacy engine that requires the old syntax.
Frequently Asked Questions
90deg, or the keyword to right. Angles are measured clockwise from the top, so 90 degrees points to the right and the first color starts at the left edge.linear-gradient(90deg, #3b82f6, #8b5cf6, #ec4899). Each stop can also carry a position such as 30% to control how much space it occupies.
Rate this Tool
Based on 0 user ratings.