ximg.es

CSS gradient generator

Pick a type, move the colour stops on the bar and copy the CSS. With “Over a photo” you see the gradient on top of an image, the usual trick to make text readable.

Click the bar to add a stop and drag it to move it. With the keyboard: arrows to move it, Delete to remove it.

CSS code

background: linear-gradient(135deg, #2563eb 0%, #db2777 100%);
Presets
Type

Selected stop

The three kinds of gradient

Colour stops

Each stop is a colour and a position: #2563eb 0%, #db2777 100%. If two stops share a position the change is sharp instead of gradual, which is how stripes are made:

background: linear-gradient(90deg, #2563eb 50%, #db2777 50%);

A gradient over an image

To make a headline readable over a photo, put a gradient from transparent black to semi-opaque black in front of it. In CSS, background layers are separated by commas and the first one is on top:

.hero {
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0.75) 100%),
    url("photo.jpg") center / cover;
}

To build it before the photo exists, use one from ximg.es: url("https://ximg.es/random/1600x900?seed=hero").

Tips

Frequently asked questions

How do you make a gradient in CSS?

With the background property and a gradient function: background: linear-gradient(135deg, #2563eb, #db2777);. No image or prefix needed.

How do I put a gradient over a background image?

Write both layers in background separated by a comma, gradient first: background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,.7)), url(photo.jpg) center / cover;

How do I make a transparent gradient?

Use colours with transparency in the stops, for example rgba(0, 0, 0, 0) to rgba(0, 0, 0, 0.8). In this generator, lower the opacity of the selected stop.

What is the difference between linear, radial and conic?

Linear progresses in one direction, radial spreads out from a point and conic turns around a centre.

Can I apply a gradient to text?

Yes: set the gradient as the text background and clip it with background-clip: text; color: transparent;.

Do CSS gradients work in every browser?

Linear and radial ones have worked everywhere for over ten years; conic ones work in all current browsers. The -webkit- prefixes are no longer needed.

More tools

See all tools · Placeholder image generator