CSS gradient generator

Linear, radial and conic gradients with draggable stops. Copy CSS or save a PNG.

Colour stops

Click the bar to add a stop, drag to move it. Arrow keys nudge the selected one.

Start from

What this tool does

A CSS gradient is a background that fades from one colour to another, written as text instead of an image. This tool lets you build one by looking at it. Pick linear, radial or conic, put colour stops on a bar, and the CSS appears underneath, ready to copy into a stylesheet. The same gradient can be saved as a PNG at any size up to 4096 pixels on a side, which is handy for a social card, a wallpaper or a design mock-up. Nothing is uploaded: the gradient is drawn in your browser.

How to use it

  1. Choose Linear, Radial or Conic, or start from one of the presets.
  2. Click the bar to add a colour stop and drag it to move it. A stop that is selected can be changed in the fields below: its colour (a picker or a hex code), its opacity and its exact position. The arrow keys move the selected stop by 1%, and with Shift by 10%.
  3. Set the direction or the centre. Turn on Repeating to tile the pattern.
  4. Press Copy CSS, or choose a size and Download PNG.

Linear, radial and conic

A linear gradient runs along a line. The angle is measured clockwise from the top: 0deg points up, 90deg points right, 180deg points down. The default here is 135deg, which runs from the top left corner to the bottom right. You can also use keywords such as to right. A corner keyword is not a fixed angle: in a square, to top right is 45deg, but in a box 200 pixels wide and 100 high the browser turns it into about 26.57deg so that the two corners that are not the target get exactly the middle colour.

A radial gradient spreads from a centre. The shape is a circle or an ellipse, and the size says where the last stop lands: the closest or farthest side, or the closest or farthest corner. With no size given, CSS uses an ellipse that reaches the farthest corner, so in a 200 by 100 box centred in the middle its radii are about 141.4 and 70.7 pixels.

A conic gradient sweeps around a centre like the hands of a clock. Stops are positions on the full turn, so 25% is a quarter turn. Setting the start angle rotates the whole sweep. A conic gradient with sharp stops is the usual way to draw a pie chart or a colour wheel in pure CSS.

Colour stops, hard edges and repeating

Each stop has a colour and a position, from 0% at the start to 100% at the end. Two stops at the same position make a hard edge instead of a blend, which is how stripes are made. The Stripes preset is repeating-linear-gradient(45deg, #fde68a 0%, #fde68a 10%, #f59e0b 10%, #f59e0b 20%): one yellow band and one orange band, 20% of the gradient line in total, tiled until the box is full. On a 100 by 100 pixel box the line is 141.42 pixels long, so the pattern repeats every 28.28 pixels.

If you list stops out of order, browsers move a stop that is earlier in the list than the one before it up to the same position. This tool avoids the surprise by always writing the stops sorted by position. Reverse mirrors every position, and Space evenly spreads the stops from 0% to 100%.

Transparency and colour format

Opacity is part of each stop. Browsers blend colours in premultiplied form, which means a fade from red to fully transparent keeps the same red and only becomes less visible: halfway, the colour is red at 50% opacity, not a dull dark red. The PNG download follows the same rule. A colour with full opacity is written as #rrggbb. With some transparency you can choose an eight digit hex code such as #ff000080, or rgba(255, 0, 0, 0.5); both mean the same thing.

Prefixes, the PNG and good to know

Current browsers understand linear-gradient() and radial-gradient() without a vendor prefix, and have done so since about 2013, so the code from this page needs no -webkit- version. The old prefixed syntax also meant something different for directions. conic-gradient() is newer (Chrome 69, Safari 12.1 and Firefox 83) and is supported by every current browser, but not by very old ones.

Two nearly identical colours can show faint bands, because a screen has only 256 steps per channel; a larger colour difference or an extra stop in between hides it. The PNG is painted on a canvas from the same stops, so what you download matches the preview. If your browser cannot draw conic gradients on a canvas directly, the page colours each pixel itself, which takes a moment on a very large size. For shadows to go with your gradient see the box shadow generator, to check that text stays readable on it use the colour tools, and to turn a vector picture into a PNG use the SVG converter.

Frequently asked questions

How do I use the CSS in my page?

Paste the line into a rule, for example `.hero { background: linear-gradient(135deg, #ff512f 0%, #f09819 100%); }`. Because it is a background image, you can combine it with `background-color` as a fallback and with `background-size` to tile a repeating pattern.

Do I need -webkit- prefixes?

No. Linear and radial gradients have worked without a prefix in browsers released since about 2013, and conic gradients were never prefixed. Only very old browsers need the old `-webkit-linear-gradient` form, which also reads its direction differently.

Why does my transparent stop look grey in other tools?

Some tools blend colours without premultiplying them, so a fade from red to transparent black passes through a dark red. CSS blends premultiplied, which keeps the red. This generator, its preview and its PNG all follow the CSS rule, so they look the same as your page will.

What is the largest PNG I can download?

4096 by 4096 pixels. The picture is made in your browser, and a larger canvas can fail or run out of memory on a phone. For a bigger image, use the CSS itself, which scales to any size for free.

Is the gradient uploaded anywhere?

No. The preview, the CSS and the PNG are all made on your device, and nothing you choose is stored or sent.