CSS Gradient Generator

Design a linear or radial gradient, preview it live and copy the CSS declaration into your own stylesheet.

The angle field applies to linear gradients. A radial gradient uses the center of its own box as the starting point.

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 stopsTo bottom (180deg)linear-gradient(90deg, #3b82f6, #8b5cf6)
radial-gradient()Two or more color stopsEllipse at center, farthest cornerradial-gradient(circle, #3b82f6, #8b5cf6)
conic-gradient()Two or more color stopsStarts at 12 o'clockconic-gradient(#3b82f6, #8b5cf6)
repeating-linear-gradient()Stops with a length or percentageTo bottom (180deg)repeating-linear-gradient(45deg, #eee 0 10px, #fff 10px 20px)

Rate this Tool

0.0/5

Based on 0 user ratings.

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.

AngleKeywordGradient line pointsFirst color appears
0degto topUpwardAt the bottom
45degto top rightUp and to the rightAt the bottom left
90degto rightTo the rightAt the left edge
180degto bottomDownwardAt the top edge
270degto leftTo the leftAt the right edge
0deg 90deg 180deg 270deg clockwise

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.

KeywordWhat it controlsTypical effect
circleShapeKeeps a perfect circle at any aspect ratio
ellipseShapeStretches to match the box; the default
closest-sideSizeEnds exactly at the nearest edge
farthest-sideSizeEnds at the farthest edge, still inside the box
closest-cornerSizeEnds at the nearest corner
farthest-cornerSizeEnds at the farthest corner; the default
at 30% 70%PositionMoves 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

MistakeWhy it failsCorrect approach
Unitless anglelinear-gradient(90, ...) is invalid; zero is the only unitless length allowedWrite 90deg
One color stopA gradient needs at least two colors to interpolateAdd a second color or a position
background-color with a gradientThe property only accepts a colorUse background-image
Fallback color lostThe background shorthand resets earlier valuesDeclare the color after, or use longhand properties
Stops out of orderBrowsers clamp positions so the fade looks compressedKeep positions ascending
Fading to transparentInterpolates toward transparent blackUse 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

Use 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.

Yes. Add as many stops as you need, separated by commas: linear-gradient(90deg, #3b82f6, #8b5cf6, #ec4899). Each stop can also carry a position such as 30% to control how much space it occupies.

Two colors that are very close produce few distinct 8-bit values across a long distance. Add an intermediate stop, reduce the distance the gradient has to cover, or overlay a subtle noise texture to break up the transitions.

Not for current browsers. Modern Chrome, Firefox, Safari and Edge all support the unprefixed functions. Old prefixed syntax only matters if you deliberately support a legacy engine.

Measure the contrast at the lightest and darkest part of the gradient, not just the middle. If either end fails, darken the gradient, add a semi-transparent scrim behind the text, or place the text on a solid panel.

No. The preview and the declaration are generated in the browser. Nothing is uploaded, and the code can be copied and used offline.