ToolsHub4u

Build a linear or radial CSS gradient

Set two or three colour stops, choose a linear angle or a radial shape, and copy a background-image rule that matches the preview.

  • Live preview
  • Linear or radial
  • Copy-ready CSS
Ready Developer & Utility
1Enter
2Adjust
3Copy result

CSS Gradient Generator

1

Gradient settings

Gradient type
deg

Only used by a linear gradient. Zero points up, 90 points right, 180 points down.

%
%
%

Only used by a radial gradient. The size is set to farthest-corner.

No data yet Live
2

CSS

Linear gradient with 2 colour stops.

Live preview

CSS

  • Stop order is increasingEach stop sits at or after the one before it.
  • The gradient has a visible spanKeep the end stop after the start stop unless you want a hard edge.
  • Radial size is fixedRadial output uses farthest-corner at the centre. CSS allows other sizes and positions, but this generator keeps the declaration simple.
Colour stops in output order
StopColourPosition
Start#2f6f5e0%
End#f6f1e7100%
Type
linear-gradient
Stops
2
Angle
135deg
CSS length
84 chars

The gradient is written as background-image rather than the background shorthand, so it does not reset background-color, repeat or position.

This page writes a CSS gradient from two or three colour stops. Choose a linear gradient and set the angle, or switch to radial and choose an ellipse or a circle. Each stop has a colour and a percentage position, and the preview updates as you move them. The output is a short rule that uses background-image, not the background shorthand.

It covers the common case: one gradient, two or three stops, a fixed centre for radial gradients. That is enough for a hero panel, a card accent or a progress bar. Layered gradients, repeating gradients, hard colour bands and colour interpolation hints are outside its scope and need to be written by hand.

Linear gradients and the angle

A linear gradient runs along a straight line. The angle is written in degrees, with 0deg pointing up, 90deg pointing right, 180deg pointing down and 270deg pointing left. The default here is 135deg, which runs from the top-left to the bottom-right. The angle field accepts any number; the output uses it as typed, without normalising it to a 0–360 range.

Stops are written as a colour and a percentage. The start stop is at 0% by default and the end stop at 100%. A middle stop is optional and sits at its own percentage. If a position is outside 0–100 it is clamped, so the gradient always has a defined start and end.

CSS sorts stops by position before painting. The generator does the same, which means the colour you called Middle can end up after the colour you called End if you give it a larger percentage. The checklist says when this happened. The output is still valid; it just may not match the mental model behind the labels.

Radial gradients

The radial option writes radial-gradient(shape farthest-corner at 50% 50%, …). The shape is ellipse or circle, the size is fixed at farthest-corner, and the centre is fixed at the middle of the box. Those three choices keep the declaration short and predictable, but they also mean the gradient cannot be positioned off-centre or sized to a side or a fixed length here.

With an ellipse, the gradient stretches to the box's aspect ratio, so the same declaration looks different on a wide card and a tall one. A circle keeps a circular shape and may leave the corners beyond the last stop. Check the preview at the size you will ship rather than at the preview's size.

A worked example

The default settings produced a two-stop linear gradient. The first colour is the site green and the second is the paper tone, at 135 degrees.

Three gradient settings and the CSS they produced
TypeStopsCSS value
Linear, 135deg#2f6f5e 0%, #f6f1e7 100%linear-gradient(135deg, #2f6f5e 0%, #f6f1e7 100%)
Linear, 90deg, middle#2f6f5e 0%, #ff0000 30%, #f6f1e7 80%linear-gradient(90deg, #2f6f5e 0%, #ff0000 30%, #f6f1e7 80%)
Radial circle#2f6f5e 0%, #f6f1e7 100%radial-gradient(circle farthest-corner at 50% 50%, #2f6f5e 0%, #f6f1e7 100%)

The third run is the one to inspect closely: a radial gradient with the same colours reads very differently from the linear version because the colour change happens in rings from the centre. The CSS length also grows from 84 to 111 characters, mostly because of the shape, size and position keywords.

When the middle stop was set to 90% and the end stop to 50%, the output put the end colour first and the middle colour last. That is correct CSS sorting, and the checklist flagged it. If the visual result surprises you, compare the percentages before changing the colours.

Positions are sorted, not relabelledThe table in the result lists stops in output order. If Middle appears last, its percentage is larger than the end stop's.

What the rule does and does not set

The declaration uses background-image inside a class called .gradient. Using the longhand rather than the background shorthand means it does not reset background-color, background-repeat, background-position or background-size. That is usually what you want when the gradient sits over an existing background colour.

The colours are written as six-digit hex. There is no alpha channel and no colour-mix hint, so a gradient cannot fade to transparent here. Add an eight-digit hex or an rgba() value by hand if you need that. The generator also writes no vendor prefixes; current browsers do not need them for linear or radial gradients.

Two stops at the same position create a hard edge rather than a smooth blend. The output remains valid, and that can be a deliberate technique for stripes. The page does not warn about it, so check the preview if you set both positions to 50%.

Using the gradient

Copy the rule or download it as a CSS file. Rename the class and adjust the selector to your component. If the gradient is behind text, check the contrast of the text against the lightest and darkest parts of the gradient; a single mid-gradient check can miss the failing end. The colour picker checks a solid pair, which is a useful approximation for each end.

For a layered look, such as a gradient plus a subtle noise image, write a second background-image layer and separate them with a comma. This page writes one layer only. The CSS minifier can compact the final rule once it is in your stylesheet.

Questions

Common questions

Short answers about this tool and its limits.

Why did the middle colour move to the end?

CSS sorts stops by position. If the middle stop has a larger percentage than the end stop, it is painted later. The output follows that order and the checklist notes it. Change the percentages if you wanted a true middle.

Can I add more than three stops?

Not in this generator. It supports a start, an optional middle and an end. Add further stops by editing the CSS value in your stylesheet, keeping each one as a colour and a position.

Why does the radial gradient look different on another card?

The radial rule uses farthest-corner at the centre. An ellipse stretches with the box's aspect ratio, so a wide card and a tall card produce different shapes. Check it at the final size.

Can the gradient fade to transparent?

Not through the form, which writes six-digit hex colours. Replace one colour with transparent or an rgba() value in the copied CSS if you need a fade. The preview will not show that edit.

Does the rule reset my background colour?

No. It uses background-image, not the background shorthand, so background-color, repeat, position and size are left alone. That makes it safe to add to a component that already has a background.

Are vendor prefixes needed?

No for current browsers. Unprefixed linear and radial gradients are supported in Chrome, Firefox, Safari and Edge. Very old browser versions are not a reason to add prefixes here.

What happens when two stops share a position?

The colour changes abruptly at that point, producing a hard edge. That is valid CSS and can be used for stripes. The page does not warn, so inspect the preview if both positions are the same.

Is the gradient saved for later?

No. It is generated in the browser and disappears when you leave the page. Copy the CSS or download it before closing the tab.