Skip to the content

Linear Gradient Generator

Set the angle and the color stops of a CSS linear gradient, watch it change and copy the linear-gradient() code.

°
Color stops

Drag a handle to move a stop. Click the bar to add one.

Presets

Share this tool:TwitterFacebookLinkedInWhatsAppEmail

How linear-gradient() is written

This is the gradient the page opens with. Its code is read from left to right:

background: linear-gradient(135deg, #f97316, #ec4899 60%, #7c3aed);
In the codeWhat it does
135degThe direction the colors travel in. Angles turn clockwise from straight up: 0deg runs to the top, 90deg to the right, 180deg to the bottom and 270deg to the left. Without an angle you get 180deg.
#f97316The first color. It has no position, so it sits at 0%: the corner the gradient comes from, here the top left.
#ec4899 60%A color with a position. Pink is reached 60% of the way along. Without the number it would sit halfway between its neighbors.
#7c3aedThe last color, at 100%: the corner the gradient runs into, here the bottom right.

Instead of an angle, CSS also takes a side. to right is the same as 90deg, to bottom as 180deg, to left as 270deg and to top as 0deg. The generator always writes the angle.

The colors run along a line through the middle of the box, and that line is made just long enough for the first and the last color to land exactly in the corners. A diagonal gradient therefore never shows a flat patch of its first color.

A corner keyword is not a fixed angle

It is tempting to read to bottom right as 135deg. That is only true on a square box.

A corner keyword aims the gradient so that its halfway color runs in a straight line between the two other corners. The angle that takes depends on the shape of the box: on a box twice as wide as it is high, to bottom right comes out at about 153deg.

On anything that is not square the two give different pictures. With 135deg the direction stays put and the halfway line misses the corners. With the keyword the line always hits them. Use the keyword when a stripe has to run from corner to corner, and the angle when the direction matters.

Color stops, hard edges for stripes and fading to transparent work the same in every kind of gradient. They are explained on the CSS gradient generator page.

See all 8