Getting a gradient right by hand means guessing at an angle, then guessing at where each colour should land, then reloading. A generator removes the guessing: you place the stops visually and read off the CSS. This guide walks through the CSS Gradient Generator option by option, shows what each control emits, and explains where its hex-only validation will stop you.
What the CSS Gradient Generator does
The tool takes between two and eight hex colour stops and produces a ready-to-paste CSS background declaration, either linear-gradient() or radial-gradient().
There are two ways in. The quick colour list is a plain comma-separated text field — type or paste hex values and import them. The visual editor below it holds one draggable handle per stop, and each handle carries both a colour and a position in percent.
The output is always two lines: a flat background: <first colour>; fallback, followed by the gradient declaration. Alongside it you get a live preview box, a colour-stop count, a Copy CSS button and a Download CSS link that writes a gradient.css file.
One piece of background helps everything else make sense. A CSS gradient is not an image file that the browser downloads; it is a <gradient> value the browser generates, and the specification defines <gradient> as a subtype of <image> (W3C CSS Images Module Level 3). That is why a gradient belongs in background or background-image and never in background-color, which only accepts a <color> (MDN).
You can follow along in the CSS Gradient Generator while you read.
How to use it
The quick list starts at #ff5f6d, #ffc371. Replace it with your own comma-separated hex colours and import them into the editor.
On import the tool spaces the stops evenly. With n colours, stop i lands at round(i × 100 / (n − 1)) — so two colours become 0% and 100%, three become 0%, 50% and 100%, five become 0/25/50/75/100.
From there you adjust:
- Drag a handle along the track to move a stop.
- Focus a handle and use the arrow keys: ±1% per press, ±10% with Shift held. Positions are always rounded to whole percent, however you set them.
- Each stop also exposes a native colour picker, a text field for the hex value, and a number input for the position.
- Add stops up to eight. The remove button switches off once you are down to two, because a gradient needs at least two colours.
The preview updates as you go. Copy CSS puts both lines on the clipboard; Download CSS saves them as gradient.css. Clear resets everything to a plain black→white linear gradient at 90°, with shape circle and centre 50/50 waiting in the radial controls.
If you are still choosing colours rather than positioning them, the Colour Palette tool is a reasonable first stop for a set of harmonious stop colours.
The options, and what they mean in CSS
Type — linear or radial, i.e. linear-gradient() or radial-gradient().
Angle (linear, 0–360, default 90) sets the direction of the gradient line. In CSS, 0deg points up and angles increase clockwise, so 90deg runs left to right and 180deg runs top to bottom (MDN). The keyword syntax (to right, to bottom) is an interchangeable way of saying the same thing (CSS-Tricks); this tool always emits degrees.
Shape (radial, circle or ellipse, default circle) — a circle keeps one radius in every direction, while an ellipse scales independently on each axis to match the box. Note the difference from CSS itself: the specification's own defaults for radial-gradient() are ellipse and farthest-corner, with the centre defaulting to center (MDN). The tool's circle default is its own choice, and it always writes the shape and centre out explicitly.
Centre X / Centre Y (radial, 0–100 each, default 50/50) are emitted as at <x>% <y>%. That position uses the same coordinate system as background-position.
Stop position (0–100) is where along the gradient axis each colour is fully reached. The spec models each stop as a line crossing the gradient line at that point, with the colours interpolated between neighbouring stops (W3C).
| Option | What it produces |
|---|---|
| Type = linear, angle = 135 | linear-gradient(135deg, …) |
| Type = radial, shape = ellipse | radial-gradient(ellipse at 50% 50%, …) |
| Centre X = 20, Centre Y = 80 | … at 20% 80% … |
Stop #2193b0 at 30 |
#2193b0 30% |
| First stop colour | background: #2193b0; (the fallback line) |
How the output is built
The quick list is split on commas, trimmed, and empty entries are dropped; what remains must be two to eight colours. Every colour is matched against a hex pattern accepting 3, 6 or 8 digits — #rgb, #rrggbb, #rrggbbaa — and lowercased, so mixed-case input still gives stable output.
Before each render the tool re-validates every stop: the colour against that same hex pattern, the position as a finite number clamped to 0–100. Anything that fails throws instead of being written into the CSS, which is also what keeps arbitrary text out of the generated declaration.
The stops are then sorted by position and joined as colour position%, and wrapped as linear-gradient(<angle>deg, …) or radial-gradient(<shape> at <x>% <y>%, …).
The flat background: line in front is the classic fallback pattern: a browser that cannot parse the gradient keeps the solid colour, and one that can simply overrides it.
The three built-in examples show the whole shape of the output. Sunset:
background: #ff5f6d;
background: linear-gradient(90deg, #ff5f6d 0%, #ffc371 100%);
Ocean:
background: #2193b0;
background: linear-gradient(135deg, #2193b0 0%, #6dd5ed 100%);
Radial glow:
background: #ffffff;
background: radial-gradient(circle at 50% 50%, #ffffff 0%, #7028e4 100%);
Limits and edge cases
- Two to eight stops. Fewer throws Need at least two colors; more throws Too many colors.
- Hex only. Named colours such as
red, plusrgb(),hsl()and CSS variables, are rejected. Convert them to hex first with the Colour Converter. - Ranges. Angle must be 0–360; radial centre coordinates and stop positions must be 0–100. Type is linear or radial only, and radial shape is circle or ellipse only.
- One error message. Any invalid value shows Use 2–8 valid HEX colours and positions from 0% to 100%. and clears the preview, the stop count and the output, rather than emitting half-valid CSS.
- A colour-picker quirk. The native picker widget only understands 7-character hex, so a 3-digit or 8-digit (alpha) stop shows as
#000000in the swatch while the real value stays in the text field and in the generated CSS. - No prefixes needed. Unprefixed
linear-gradient()andradial-gradient()are supported in all current major browsers (Can I Use), so the copied CSS works as-is.
Privacy
Everything — splitting the list, validating colours and positions, assembling the gradient string — happens in the page's own JavaScript. There is no upload, no network request and no server-side storage, and the downloadable gradient.css is built in the browser and handed to the download as a local object URL. Nothing is left to delete afterwards: closing the tab ends it.
FAQ
Why doesn't my gradient work when I put it in background-color?
Because a gradient is not a colour. CSS defines gradients as <image> values generated by the browser, and background-color only accepts a <color> (MDN). Use background or background-image instead — which is exactly what the generator's second output line does.
What does the angle actually mean — is 90deg the same as "to right"?
The angle sets the direction of the gradient line. 0deg points up and angles increase clockwise, so 90deg points right and 180deg points down (MDN). 90deg and to right describe the same direction; the keyword form is just an alternative spelling (CSS-Tricks). This tool always writes degrees.
Can I use named colours, rgb() or hsl() in this generator?
No. Colours must be 3-, 6- or 8-digit hex. Anything else is rejected before it reaches the output. Convert the value first with the Colour Converter, then paste the hex in.
How do I add transparency to a gradient colour?
Use the 8-digit form, #rrggbbaa, where the last two digits are the alpha channel — the tool accepts it in the quick list and in a stop's text field. The native colour swatch will show #000000 for such a value, but the text field and the generated CSS keep what you typed.
What's the difference between circle and ellipse for a radial gradient?
A circle has the same radius in every direction; an ellipse scales independently per axis, so it follows the box's proportions (MDN). CSS's own default is ellipse; the tool defaults to circle and always writes the keyword out, so the emitted CSS says what you chose.
How many colour stops can I use?
Between two and eight. Below two there is nothing to interpolate, and the remove button is disabled at two stops for that reason; above eight the tool refuses the input. CSS itself does not impose this ceiling — it is the generator's range.
Do I still need -webkit- or -moz- prefixes?
Not for current browsers: unprefixed gradient functions are supported across all major ones (Can I Use). Prefixes only mattered for legacy versions. The tool emits unprefixed CSS.
Why are there two background lines in the copied CSS?
The first line is a solid fallback using your first stop's colour, and the second is the gradient. A browser that understands the gradient applies it and the fallback is overridden; one that does not simply keeps the solid colour. Keep both lines in that order when you paste them.