CSS gradient generator

Choose two colours and an angle, preview the gradient live and copy the CSS.

How gradient CSS works

A CSS gradient is not an image file. It is an instruction the browser paints itself, which means it costs no download, scales to any size without blurring, and can be changed by editing one line. The syntax is a function used as a background value:

background: linear-gradient(angle, first colour, second colour);

The browser blends smoothly from the first colour to the second along the direction you give. A radial gradient works the same way but blends outwards from the centre, so it takes a shape keyword (usually circle) instead of an angle. This tool writes the declaration for you as you adjust the controls, so what you copy is exactly what you previewed. Paste it onto any element with a size, such as a header, a button or the page body, and it will fill whatever space that element occupies. Because a gradient is technically an image value, you can also use it anywhere CSS accepts one, including background-image and even border-image.

Understanding the angle

Gradient angles follow a compass-style convention that catches people out. 0deg points up, so the gradient runs from bottom to top, with the first colour at the bottom. Turning clockwise, 90deg points right (left to right), 180deg points down (top to bottom) and 270deg points left (right to left). The diagonal angles fall in between: 135deg travels from the top left corner towards the bottom right, which is a popular choice for hero banners because it echoes reading direction. If your gradient looks upside down, you almost always need the angle plus or minus 180.

Worked examples

Each of these was produced with the controls above: pick the two colours, set the type and angle, and copy the line. The hex codes are written in uppercase purely for readability; CSS treats upper and lower case identically.

Purple to blue banner, left to right
background: linear-gradient(90deg, #6A11CB, #2575FC);
Sunset header on the diagonal
background: linear-gradient(135deg, #FF512F, #F09819);
Soft radial spotlight for a card background
background: radial-gradient(circle, #FFFFFF, #C9D6FF);

Making gradients look good

The gradients that age best blend colours that are already related. Two shades of the same hue, or two hues within about 60 degrees of each other on the colour wheel, blend cleanly; opposite hues pass through a muddy grey in the middle, which is why red-to-green gradients rarely look intentional. If you need distant hues, add a stop between them to steer the route. Watch for banding on large areas: when the two colours are far apart in lightness, screens run out of in-between shades and you see stripes, so either bring the colours closer or shorten the distance the gradient covers. Finally, if text sits on top of a gradient, check it against the lightest and the darkest ends, because contrast that passes at one edge can fail at the other. A safe pattern is to keep gradients for decorative surfaces and put text on a solid overlay or a consistently dark region. The palette generator on this site is a quick way to find pairs of related colours worth blending, and the analogous scheme in particular tends to produce natural gradient pairs.

Frequently asked questions

What does the angle mean?

The angle sets the direction the gradient travels. 0deg runs from bottom to top, 90deg from left to right, 180deg from top to bottom, and 270deg from right to left. Values in between tilt it: 135deg runs from the top left towards the bottom right.

What is the difference between linear and radial?

A linear gradient blends the colours along a straight line at your chosen angle. A radial gradient starts with the first colour at the centre and blends outwards to the second colour at the edges, so it has no angle.

Can I use more than two colours?

Yes. CSS gradients accept any number of comma-separated colour stops, so you can copy the generated code and add extra colours in the middle, optionally with percentage positions like #FF512F 30% to control where each stop sits.

Why does my gradient show visible bands?

Banding appears when two colours are far apart in lightness and the blend is stretched over a large area, because screens can only show so many in-between shades. Choosing colours closer together, shortening the gradient or adding an intermediate colour stop all help.

Do all browsers support these gradients?

Yes. Unprefixed linear-gradient and radial-gradient have worked in every major browser since around 2013, including Chrome, Firefox, Safari and Edge, so no vendor prefixes or fallbacks are needed for modern audiences.

Related tools