CSS Gradient Generator

This CSS gradient generator lets you design a linear, radial or conic gradient by dragging colour stops, then copy the CSS or Tailwind class or download it as an image.

Colour stops

Tap the bar to add · drag to move

background: #9e47bf;
background: linear-gradient(90deg, #4f46e5 0%, #ec4899 100%);

Download as an image

Edit an existing gradient

Presets

Why use this gradient generator?

This generator covers all of CSS gradients, not just two-colour backgrounds: linear, radial and conic gradients, repeating patterns, opacity and hard stops, and blending in OKLab or OKLCH so the middle doesn't turn grey. It writes exact code for plain CSS and both Tailwind versions, reads existing gradient CSS back in for editing, and exports a PNG painted from the same maths as the browser. It runs in your browser and remembers your last gradient on this device.

How to make a CSS gradient

  1. Pick a preset, press Random, or start from the default and choose Linear, Radial or Conic.
  2. Tap the colour bar to add stops, drag them to move, and set each stop's colour and opacity.
  3. Set the angle with the dial or arrows, or drag the centre on the preview. Try OKLCH if the middle looks dull.
  4. Copy the CSS or Tailwind class, grab a gradient text or border snippet, or download an image.

CSS gradient syntax

A gradient is an image, so it goes in background or background-image. The first argument sets the direction or shape, and the rest are colour stops: a colour and an optional position.

/* a line at 135deg from purple to orange */
background: linear-gradient(135deg, #7c3aed 0%, #f97316 100%);

/* a circle from the top-left corner */
background: radial-gradient(circle at 20% 20%, #fde68a, #b45309);

/* a colour wheel around the centre */
background: conic-gradient(from 0deg in oklch longer hue, red, red);
FunctionColours runGood for
linear-gradient()Along a straight line at an angleBackgrounds, buttons, overlays on photos, hero sections
radial-gradient()Outward from a centre, as a circle or ellipseSpotlights, glows, vignettes, soft shapes
conic-gradient()Around a centre, like a clock handColour wheels, pie charts, loading rings, checkerboards

Linear angles start at 0deg pointing up and turn clockwise, so 90deg runs left to right and the default 180deg runs top to bottom. Stop positions are percentages of the gradient line; for a conic gradient they can also be angles (90deg = 25%). Leave positions out and the stops are spaced evenly.

Smooth gradients without a grey middle

Browsers blend gradient colours in the sRGB colour space unless told otherwise, and in sRGB the halfway point between two strong opposite colours is a muddy grey: blue to yellow passes through grey, red to green through brown. CSS can now blend in perceptual colour spaces instead. in oklab gives an even, natural blend; in oklch keeps the colours saturated by travelling around the colour wheel, and in oklch longer hue goes the long way round for rainbows. Try the Blend colours in setting with the Rainbow and Grape soda presets to see the difference. Need precise colour values first? The colour converter translates HEX, RGB, HSL and OKLCH, and the colour palette generator builds matching sets of colours.

Hard stops, stripes and repeating gradients

Two stops at the same position switch colour with a crisp edge. A stop can also take two positions, which is shorthand for that: #2563eb 0 50%, #facc15 50% 100%. Add repeating- to the function and the stops repeat until the box is full, which is how stripes, rings and checkerboards are made without any images:

/* diagonal warning stripes */
background: repeating-linear-gradient(45deg, #f59e0b 0 12px, #1f2937 12px 24px);

/* a checkerboard */
background: repeating-conic-gradient(#e5e7eb 0% 25%, #ffffff 0% 50%) 0 0 / 32px 32px;

Gradient overlays on images

Backgrounds stack, so a semi-transparent gradient can sit on top of a photo to keep text readable. List the gradient first, then the image:

background:
  linear-gradient(to bottom, rgb(0 0 0 / 0) 40%, rgb(0 0 0 / 0.7)),
  url("photo.jpg") center / cover;

Use the Opacity slider on a stop to make fades like this, and the Fade out preset as a starting point. To pick colours straight from the photo, open it in the image colour picker.

Gradients in Tailwind CSS

  • Any Tailwind version: an arbitrary value holds the exact CSS, with underscores for spaces: bg-[linear-gradient(90deg,#4f46e5_0%,#ec4899_100%)].
  • Tailwind v4: bg-linear-90 from-[#4f46e5] to-[#ec4899], plus bg-radial and bg-conic. v4 blends in OKLab by default, so add /srgb to match plain CSS or /oklch for vivid blends.
  • Tailwind v3: bg-gradient-to-r from-[#4f46e5] via-… to-[#ec4899] for the eight directions, with stop positions such as from-10%.

The Tailwind tab writes whichever of these fit your gradient. To shrink the finished stylesheet, run it through the code minifier.

Browser support

First browser versions that support each feature (Chrome and Edge share version numbers):

FeatureChrome, EdgeFirefoxSafari
linear-gradient(), radial-gradient()26166.1
conic-gradient()698312.1
Two positions on one stop (red 0 50%)716412.1
Blending in oklab / oklch11112716.2

Source: MDN browser compatibility data. With fallbacks on, the copied CSS starts with a solid colour and, for OKLab or OKLCH, a plain sRGB gradient, so older browsers ignore the line they don't understand and keep the one before it.

Frequently asked questions

How do I create a gradient in CSS?

Set a gradient function as the background, for example background: linear-gradient(90deg, #4f46e5, #ec4899);. The first value is the direction and the rest are colour stops, each with an optional position. Build it visually above, then copy the CSS: it includes a solid fallback colour for very old browsers.

What are the three types of CSS gradients?

linear-gradient() blends along a straight line at an angle. radial-gradient() spreads outward from a centre point as a circle or an ellipse. conic-gradient() sweeps around a centre point like the hands of a clock, which is how colour wheels and pie charts are drawn. Each has a repeating- version that repeats the stops to fill the box, for stripes and rings.

Which direction does the angle of a linear gradient go?

0deg points up (to top), 90deg to the right, 180deg down (the default) and 270deg to the left; angles turn clockwise. The keywords to right and to bottom are the same as 90deg and 180deg, but corner keywords such as to top right aim at the box's corner, so they equal 45deg only in a square box.

How do I make a gradient fade to transparent?

Give one stop a transparent colour, such as linear-gradient(to bottom, rgb(0 0 0 / 0), rgb(0 0 0 / 0.75)) or #00000000. Current browsers blend transparency without the grey fringe older ones showed with the transparent keyword, but using the same colour with zero opacity is the safest. Layering such a fade over a photo keeps white text readable: background: linear-gradient(…), url(photo.jpg).

How do I make gradient text with CSS?

Paint the gradient as the background of the text and clip it to the letters: background: linear-gradient(…); -webkit-background-clip: text; background-clip: text; color: transparent;. The Text tab of the output gives you that snippet for your gradient. Keep enough contrast with the page, because the lightest part of the gradient decides how readable the text is.

How do I make a hard colour stop or stripes?

Put two stops at the same position and the colour changes with a sharp edge instead of a blend: linear-gradient(90deg, #2563eb 50%, #facc15 50%). For stripes, repeat a short pattern: repeating-linear-gradient(45deg, #f59e0b 0 5%, #1f2937 5% 10%). In the editor, drag two stops onto the same spot, or start from the Hard split and Stripes presets.

Why does my gradient look grey or muddy in the middle?

By default browsers blend colours in the sRGB colour space, and the halfway point between two vivid opposite colours, such as blue and yellow, is a dull grey. Blending in OKLab or OKLCH keeps the middle bright: linear-gradient(90deg in oklch, blue, yellow). Chrome and Edge 111, Safari 16.2 and Firefox 127 support this syntax, and the CSS this tool writes includes a plain sRGB line before it for older browsers.

How do I use a CSS gradient in Tailwind?

Any gradient works as an arbitrary value in Tailwind v3 and v4: bg-[linear-gradient(90deg,#4f46e5_0%,#ec4899_100%)], with underscores instead of spaces. Tailwind v4 also has utilities such as bg-linear-90 from-… via-… to-…, which blend in OKLab unless you add /srgb; Tailwind v3 has bg-gradient-to-r with from-, via- and to- colours. The Tailwind tab shows every form that fits your gradient.

Can you animate a CSS gradient?

Browsers don't animate between two background-image gradients directly. Two techniques work: make the gradient larger than the element (background-size: 200% 200%) and animate background-position, or register the colours or angle as custom properties with @property and animate those. @property works in Chrome and Edge, Safari 16.4 and later, and Firefox 128 and later.

How do I add a gradient border with rounded corners?

Give the element a transparent border and two background layers: a solid colour clipped to the padding box and the gradient clipped to the border box, as in background: linear-gradient(#fff, #fff) padding-box, linear-gradient(…) border-box;. Unlike border-image, this keeps border-radius working. The Border tab writes it for your gradient.

Can I download the gradient as an image?

Yes. Choose a size, such as 1920 × 1080, 4K, a square post or a phone wallpaper, or type your own, and download a PNG or JPG. The image is painted pixel by pixel from the same maths as the CSS, including OKLCH blending, repeating gradients and transparency, so it matches what the browser shows. It's made on your device; nothing is uploaded.

Do CSS gradients work in all browsers?

Linear and radial gradients work in every browser in use today. Conic gradients need Chrome 69, Firefox 83 or Safari 12.1 or later, and blending in OKLab or OKLCH needs Chrome 111, Safari 16.2 or Firefox 127. The copied CSS lists a solid colour first and, for OKLab and OKLCH, a plain sRGB gradient next, so older browsers still show something close.

Advertisement